Search code examples
c#xmlreadxml

Problem with node.GetElementsByTagName in C#


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!


Solution

  • 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.