Корневой элемент отсутствует при загрузке XmlDocument из потока

У меня есть следующий код:

var XmlDoc = new XmlDocument();
Console.WriteLine();
Console.WriteLine(response.ReadToEnd());
Console.WriteLine();

// setup the XML namespace manager
XmlNamespaceManager mgr = new XmlNamespaceManager(XmlDoc.NameTable);
// add the relevant namespaces to the XML namespace manager
mgr.AddNamespace("ns", "http://triblue.com/SeriousPayments/");
XmlDoc.LoadXml(response.ReadToEnd());
XmlElement NodePath = (XmlElement)XmlDoc.SelectSingleNode("/ns:Response", mgr);

while (NodePath != null)
  {
      foreach (XmlNode Xml_Node in NodePath)
      {
          Console.WriteLine(Xml_Node.Name + " " + Xml_Node.InnerText);
      }
  }

Я получаю:

Корневой элемент отсутствует.

в:

XmlDoc.LoadXml(response.ReadToEnd());

Мой XML выглядит так:

<?xml version="1.0" encoding="utf-8"?>
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://triblue.com/SeriousPayments/">
    <Result>0</Result>
    <Message>Pending</Message>
    <PNRef>230828</PNRef>
    <ExtData>InvNum=786</ExtData>
</Response>

Я потерялся. Может кто подскажет, что я делаю не так? Я знаю, что у меня это работало раньше, поэтому я не уверен, что я напортачил.

Как всегда, спасибо!

* Причина моего редактирования после того, как я получил ответ * *

Мне нужно было изменить строку:

XmlElement NodePath = (XmlElement)XmlDoc.SelectSingleNode("/ns:Response");

на:

XmlElement NodePath = (XmlElement)XmlDoc.SelectSingleNode("/ns:Response", mgr);

Это не будет работать без этого.

7
задан Stécy 11 July 2013 в 14:40
поделиться