У меня есть следующий код:
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);
Это не будет работать без него.