Hi,
There are a few options. You can simply use
string.Replace(Environment.Newline, " "). If you want to keep the xml nicely
formatted you can format it using an XmlWriter. You can also create a simple
recursive parser that simply removes the line breaks from just text nodes.
protected override void OnLoad(EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
foreach (XmlNode node in doc.ChildNodes)
StripRN(node);
Console.Write(doc.InnerXml);
}
void StripRN(XmlNode node)
{
if (node.NodeType == XmlNodeType.Text)
node.Value = node.Value.Replace(Environment.NewLine, " ");
foreach (XmlNode childNode in node.ChildNodes)
StripRN(childNode);
}
Depending on your xml you may encounter
--
Happy Coding!
Morten Wennevik [C# MVP]
Nirmal Singh said:
I am reading in a text node from an XML file which is on several lines.
How can I get read of newline characters from this string?
NiMuSi