Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > XML parse

Reply
Thread Tools

XML parse

 
 
Stan SR
Guest
Posts: n/a
 
      05-21-2007
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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      05-21-2007
Stan SR wrote:

> <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/prrocessResponse/pr:myResult",
namespaceManager);


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Stan SR
Guest
Posts: n/a
 
      05-21-2007
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/prrocessResponse", nsmg);

in fact, I need to get the this result

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


Where 's the problem ?
Stan

"Martin Honnen"

> 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/prrocessResponse/pr:myResult",
> namespaceManager);
>
>
> --


 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      05-21-2007
Stan SR wrote:

> 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/"

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compare that URL to this

> nsmg.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope");

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




--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Stan SR
Guest
Posts: n/a
 
      05-21-2007

"Martin Honnen"

>> Here's the correct header of my xml file
>> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"

> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Compare that URL to this
>
>> nsmg.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope");

> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to parse a xml document which has a combination of XML XQuery andXPath beginner Java 13 08-30-2008 01:50 PM
optparse: parse v. parse! ?? 7stud -- Ruby 3 02-20-2008 05:20 AM
blocking I/O with javax.xml.parsers.DocumentBuilder.parse() and javax.xml.transform.Transformer.transform() jazzdman@gmail.com Java 1 03-27-2005 06:56 AM
Capture XML post and parse XML on pageload neil ASP .Net 0 03-16-2005 05:28 PM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM



Advertisments