473,325 Members | 2,774 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,325 software developers and data experts.

Using XPath against serialized object

Don
Hi:

I have the following web service object serialized into my XML DOM. With
XPath, I am able to select '//document/Info/ID' from the XML. Adding the
namespace is where I get a problem(see XML below).
--------------------------
<document>
<Info xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID>416</LMID>
<NUM>1</BNUM>
</Info>

</document>

-------------------------------

Using the same XPath, nothing is returned. There are two ways I'd like to
try to solve this.

1) Try to remove the namespace (that seems to cause the problem)

2) Or make my XPath namespace aware.

<document>
<Info xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID
xmlns="http://web/DataSubSystemWebService/Services">416</LMID>
<NUM
xmlns="http://web/DataSubSystemWebService/Services">1</BNUM>

</Info>

</document>

-------------------------------

Thanks in advance,

Don
Nov 12 '05 #1
1 1576
"Don" <do*************@hotmail.com> wrote in message news:O2****************@tk2msftngp13.phx.gbl...
I am able to select '//document/Info/ID' from the XML. Adding the
namespace is where I get a problem(see XML below).


To make your XPath work with namespaces you must create an
XmlNamespaceManager and pass that as an argument to Select-
Nodes( ), there's an overload of that method that accepts an Xml-
NamespaceManager for this purpose.

Additionally, since you have declared default namespaces, you
must associate a prefix with the namespaces in the XPath query.
It's a practical matter -- b/c you can't type an empty string as a
namespace prefix in an XPath expression.

For example, in VB.NET,

' Given xmlDoc is an XmlDocument containing your XML.
'
Dim nsMan As XmlNamespaceManager = _
New XmlNamespaceManager( xmlDoc.NameTable)
nsMan.AddNamespace( "ns1", "http://web/DataSubSystemWebService/Services")
Dim nodes As XmlNodeList
nodes = xmlDoc.SelectNodes( "//document/Info/ns1:ID", nsMan)
'
' Enumerate over nodes with For Each or other loop to
' process each resulting XmlNode, if any.

See also the following article, I know you've overcome this before, :-)

http://groups-beta.google.com/group/...b?dmode=source
Derek Harmon
Nov 12 '05 #2

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

Similar topics

0
by: bdinmstig | last post by:
I am building various framework components for my team to use in development, and one of those components is a Facade for reading/writing user preferences. The idea is that preference settings...
1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
2
by: hazz | last post by:
Does anyone have any ideas on how to implement what has been suggested for my 'rules engine'? thx, -hazz the following are rules in the sql server table, one row for each rule. Table Column ...
6
by: Chua Wen Ching | last post by:
Hi there, I had this xml file with me (not yet consider implementing xml namespaces yet). <?xml version='1.0'?> <Object> <Windows> <EID>1</EID> <EDesc>Error 1</EDesc> </Windows>
0
by: Pierre | last post by:
Hi, I'm trying to select specific nodes from a XmlDocument filled with a serialized object and to insert these nodes into another XmlDocument. The object is well serialized (see below). From a...
1
by: hazz | last post by:
This is what Nick Malik suggested from the c# newsgroup. Now that the hectic workweek is over, I can begin to appreciate what he said and break it down into constituent elements to solve. If anyone...
6
by: Derek Hart | last post by:
I bring in an xml file into vb.net by using xmlDoc.LoadXml(XMLString) - I run xpath statements against the xml file to grab data from it, so I use, as an example, //Vehicles/Vehicles/@make to get...
0
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.