tags:

views:

661

answers:

3

I have a really simple XML file that I'm trying to read, but I can't seem to get it working. Here is the XML file:

<?xml version="1.0"?> <Results><One>45364634</One><Two>-1</Two><Three>B</Three></Results>

I am trying to get the contents of two like this:

XmlNode node = doc.DocumentElement.SelectSingleNode("/Results/Two");

or

XmlNodeList list = doc.GetElementsByTagName("Two");

Neither is working. When I copy paste the XML as a string into the XmlDocument, then it works. However, when I use the string I pull out of the response (where I'm getting the XML from), it doesn't work.

I'm wondering if it's something weird like a character issue or not looking at the correct root, but I can't figure it out. Any ideas?

Thanks!

+1  A: 

Check the Xml file encoding ...

Is it ansi? utf-8 or utf-16?

Check if the xml was loaded from the file at all. Check if there is any error, see if the document was populated.

I think the document is not being populated when loading from the file.

Shafqat Ahmed
I thought about an encoding problem too.Although, if it's an encoding problem, there should be an exception thrown when loading the document (since it looks like regular ascii, utf8 should work fine but utf-16 could be a problem).
Yann Schwartz
A: 

By your use of the word "response" I am assuming you are passing the xml via http? If so, try using HttpServerUtility.HtmlDecode( xml ) see if that works

Simon Wilson
A: 

Bleh.

Turns out I was returning an XML document within an XML document. That's why printing to the screen looked ok but I couldn't pull it out.

Thanks guys.

Amber Shah