XML XPath: récupérer un élément quand il y a des namespaces
Bonjour,
j'ai un fichier xml qui ressemble a ca :
Code:
1 2 3 4 5 6 7 8 9
| <Output xmlns="toto.blabla://" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Data>-1</Data>
<Result xmlns:a="http://toto.blabla/CLSAPI3">
<a:ResultCode>INTERNAL_ERROR</a:ResultCode>
<a:ResultMessage>OK</a:ResultMessage>
<a:ResultCodeEx>CLS_SE_NO_OPEN_CALL</a:ResultCodeEx>
</Result>
<Exception i:nil="true" xmlns:a="http://schemas.datacontract.org/2004/07/System" />
</Output> |
j'aimerais récupérer le resultcode sauf que j'y arrive pas.
voici ce que je mets :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| void RecupData(XmlDocument doc){
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc1.NameTable);
nsmgr.AddNamespace("Toto", "toto.blabla://");
nsmgr.AddNamespace("a", @"http://toto.blabla/CLSAPI3");
string xpathdoc = "/Output/Result/a:ResultCode";
XmlNode resultcode = doc1.SelectSingleNode(xpathdoc,nsmgr);
string result = resultcode.InnerText;
} |
en fait le resucode est vide.
est-ce que quelqu'un aurait une solution ?