XML parse

S

Stan SR

Hi,

I have an xml file with these nodes
<soap:Envelope xmlns:soap="http://blabla">
<soap:body>
<ProcessResponse xmlns="http://anotherblabla">
<myResult>
<data _1>1</dada_1>
<data_2>2</data_2>
</myResult>
</ProcessResponse>
</soap:Body>
<soap:Envelope>


I need to perform a selectNode on myResult
Like
XmlNodeList
nodes=doc.SelectNodes("/Envelope/body/ProcessResponse/myResult");

But I m blocked with the different namespaces (blabla and anotherblabla).
How can get my nodes selection when there are namespaces on some nodes ?
Thanks

Stan
 
M

Martin Honnen

Stan said:
<soap:Envelope xmlns:soap="http://blabla">
<soap:body>
<ProcessResponse xmlns="http://anotherblabla">
<myResult>
<data _1>1</dada_1>
<data_2>2</data_2>
</myResult>
</ProcessResponse>
</soap:Body>
<soap:Envelope>


I need to perform a selectNode on myResult
Like
XmlNodeList
nodes=doc.SelectNodes("/Envelope/body/ProcessResponse/myResult");

But I m blocked with the different namespaces (blabla and anotherblabla).
How can get my nodes selection when there are namespaces on some nodes ?

Use an XmlNamespaceManager and AddNamespace, assuming you have this
snippet of XML:

<soap:Envelope xmlns:soap="http://blabla">
<soap:Body>
<ProcessResponse xmlns="http://anotherblabla">
<myResult>
<data_1>1</data_1>
<data_2>2</data_2>
</myResult>
</ProcessResponse>
</soap:Body>
</soap:Envelope>

then you can use e.g.

XmlNamespaceManager namespaceManager = new
XmlNamespaceManager(xmlDocument.NameTable);
namespaceManager.AddNamespace("soap", "http://blabla");
namespaceManager.AddNamespace("pr", "http://anotherblabla");
XmlNodeList nodes =
xmlDocument.SelectNodes("soap:Envelope/soap:Body/pr:processResponse/pr:myResult",
namespaceManager);
 
S

Stan SR

Thanks Martin,

I ve tried your code but it still doesn't work for me ...

Here's the correct header of my xml file
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
soap:encodingStyle="http//schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<ProcessResponse xmlns="http://www.csc.com/graphtalk/">
<POGEST>
<ReturnStatus>
<BUSINESS_STATUS>WM_SUCCESS</BUSINESS_STATUS>
</ReturnStatus>
<Data>
...
</ProcessResponse>
</soap:Body>
</soap:Envelope>

So here's my code

XmlNamespaceManager nsmg = new XmlNamespaceManager(doc.NameTable);
nsmg.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope");
nsmg.AddNamespace("pr", "http://www.csc.com/graphtalk/");
XmlNodeList nodestatut =
doc.SelectNodes("soap:Envelope/soap:Body/pr:processResponse", nsmg);

in fact, I need to get the this result

XmlNodeList nodestatut =
doc.SelectNodes("soap:Envelope/soap:Body/pr:processResponse/pr:pOGEST/pr:ReturnStatus",
nsmg);


Where 's the problem ? :-(
Stan

"Martin Honnen"
 
M

Martin Honnen

S

Stan SR

"Martin Honnen"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compare that URL to this

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
URL and you will see that the trailing slash is missing, that way you
can't find the element.


Yes, I ve found the issue (and you were right)...
Many thanks.

Stan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top