473,382 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

XML parse

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

May 21 '07 #1
4 1457
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/pr:ProcessResponse/pr:myResult",
namespaceManager);
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 21 '07 #2
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"
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);
--
May 21 '07 #3
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/
May 21 '07 #4

"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
May 21 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to...
24
by: | last post by:
Hi, I need to read a big CSV file, where different fields should be converted to different types, such as int, double, datetime, SqlMoney, etc. I have an array, which describes the fields and...
3
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
3
by: Mark | last post by:
How do you parse a currency string to a decimal? I'd like to avoid having to parse the number out, removing the $ manually. That sounds like a hack. There are times that this string will be...
14
by: Jon Davis | last post by:
I have put my users through so much crap with this bug it is an absolute shame. I have a product that reads/writes RSS 2.0 documents, among other things. The RSS 2.0 spec mandates an en-US style...
3
by: Bob Rundle | last post by:
I would like to get something like this to work... Type t = FindMyType(); // might be int, float, double, etc string s = "1233"; object v = t.Parse(s); This doesn't work of couse, Parse is...
3
by: Slonocode | last post by:
I have some textboxes bound to an access db. I wanted to format the textboxes that displayed currency and date info so I did the following: Dim WithEvents oBidAmt As Binding oBidAmt = New...
5
by: js | last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss". I need to parse the text using System.DateTime.Parse() function with custom format. I got an error using the following code. ...
2
by: Samuel R. Neff | last post by:
I'm using a quasi open-source project and am running into an exception in double.Parse which is effectively this: double.Parse(double.MinValue.ToString()) System.OverflowException: Value was...
3
by: Peter Duniho | last post by:
I'm sure there's a good explanation for this, but I can't figure it out. I tried using DateTime.Parse() with a custom DateTimeFormatInfo instance, in which I'd replaced the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.