473,756 Members | 2,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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/DataSubSystemWe bService/Services">416</LMID>
<NUM
xmlns="http://web/DataSubSystemWe bService/Services">1</BNUM>

</Info>

</document>

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

Thanks in advance,

Don
Nov 12 '05 #1
1 1608
"Don" <do************ *@hotmail.com> wrote in message news:O2******** ********@tk2msf tngp13.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
XmlNamespaceMan ager and pass that as an argument to Select-
Nodes( ), there's an overload of that method that accepts an Xml-
NamespaceManage r 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 XmlNamespaceMan ager = _
New XmlNamespaceMan ager( xmlDoc.NameTabl e)
nsMan.AddNamesp ace( "ns1", "http://web/DataSubSystemWe bService/Services")
Dim nodes As XmlNodeList
nodes = xmlDoc.SelectNo des( "//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
1823
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 are stored in a free-format XML document (in memory for the life of the session) and persisted to a database (as free text) on exit. I have taught my developers the basics of XPath, however I don't want to have to review XMLDOM code all over the...
1
6824
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 elements, attributes, ".", and "..", plus also the "" predicate format is supported - however, only one predicate per path step is supported, and expr must be a relative path. 2. Poor performance
2
2882
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 - "xmlns="http://tempuri.org/nameOfRoot.xsd" I have no idea what its pointing to & what is tempuri.org? So when this tag is in my xml tag my xpath query never works. But when I delete it work fine.
2
1021
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 op value score Buy Budget > 500000 10 Buy Budget < 500000 5 Sell In6mths = Yes 10 Sell In6mths = No 5
6
15510
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
1989
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 normal XmlDoc to another I don't have any issue, the nodes are copied but then with this serialized object it doesn't seem to work. The C# code:
1
1668
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 has any implementation examples related to what Nick describes below, they would be ppreciated. -hazz One thing you could do is to place your rules in a database. Each rule consists of an XPath expression for the operand, and operator, the...
6
2015
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 the make of the car. But then I pass a specific node from xmlDoc into another function, not the whole xmlDoc, just a node from it. And if I run an xpath against it, I have to use .// (has a period at the beginning) so it does not grab info from...
0
6616
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 object and transport it over the Internet using HTTP between a client and a server. On the other end, deserialization reconstructs the object from the stream. XML serialization serializes only the public fields and property values of an object...
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.