Escape characters in InnerXml

I

Ian Walsh

XmlDocument oXmlDoc = new XmlDocument();
oXmlDoc.Load(filename);
node = oXmlDoc.SelectSingleNode("//config/ldap/userpath");
Console.Write(node.InnerXml);

The value I get is:

\r\n\t\t\tOU=Walshy,OU=GroupServices,OU=organizations,OU=Portal,DC=portaladdev,DC=intranet,DC=local\r\n\t\t

I know this is because of the format of the xml doc. The question is,
how do I get the value from the element without the escape characters?

Example of xml doc is as follows:

<?xml version="1.0" encoding="UTF-8" ?>
<config>
<ldap>
<userpath>
OU=Walshy,OU=GroupServices,OU=organizations,OU=Portal,DC=portaladdev,DC=intranet,DC=local
</userpath>
</ldap>
</config>

Thanks.
 
J

Jon Skeet [C# MVP]

Ian Walsh said:
XmlDocument oXmlDoc = new XmlDocument();
oXmlDoc.Load(filename);
node = oXmlDoc.SelectSingleNode("//config/ldap/userpath");
Console.Write(node.InnerXml);

The value I get is:

\r\n\t\t\tOU=Walshy,OU=GroupServices,OU=organizations,OU=Portal,DC=po
rtaladdev,DC=intranet,DC=local\r\n\t\t

My guess is that you're looking in the debugger.
I know this is because of the format of the xml doc. The question is,
how do I get the value from the element without the escape characters?

The escape characters aren't actually there - the actual tabs, carriage
returns etc are there though. If you don't want them, use String.Trim.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top