473,725 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with Xpath when adding namespace

I have a simple XML file that I have been using:

<component name="test">
<class name="class"/>
<component>

Up till now, the Xpath of "//component[@name="test"]/class[@name="class"]"
worked well to select the <class> tag.

Recently we added a namespace to the <component> tag:

<component xmlns=http://tempuri.org/test.xsd name="test">

Now, the Xpath no longer works from with in VB.NET. However, it is fine
when I check it via XMPSpy.

I tried adding a XMLNamespaceMan ger to the SelectSingleNod e, but to no
avail. any suggestions?

TIA

David
Nov 11 '05 #1
2 6152
Every one hits this problem at least once.

You can change you XPath to:
1.
"//*[local-name()='compone nt'][@name="test"]/*[local-name()='class'][@name="
class"]"
or
2. "//test:component[@name="test"]/test:class[@name="class"]"
XmlNamespaceMan ager nsman = new XmlNamespaceMan ager();
nsman.AddNamesp ace("test", http://tempuri.org/test.xsd);

Sergey
--
This posting is provided "AS IS" with no warranties, and confers no rights.

"David Williams" <dw*******@stro hlsystems.com> wrote in message
news:eh******** ******@tk2msftn gp13.phx.gbl...
I have a simple XML file that I have been using:

<component name="test">
<class name="class"/>
<component>

Up till now, the Xpath of "//component[@name="test"]/class[@name="class"]"
worked well to select the <class> tag.

Recently we added a namespace to the <component> tag:

<component xmlns=http://tempuri.org/test.xsd name="test">

Now, the Xpath no longer works from with in VB.NET. However, it is fine
when I check it via XMPSpy.

I tried adding a XMLNamespaceMan ger to the SelectSingleNod e, but to no
avail. any suggestions?

TIA

David

Nov 11 '05 #2
You'll find an example of using namespaces (default and local) and XPath
together in .NET at the following URL:

http://www.xmlforasp.net/codeSection.aspx?csID=7

HTH,
Dan Wahlin

Wahlin Consulting
Microsoft MVP - ASP.NET and XML Web Services
http://www.xmlforasp.net

"David Williams" <dw*******@stro hlsystems.com> wrote in message
news:eh******** ******@tk2msftn gp13.phx.gbl...
I have a simple XML file that I have been using:

<component name="test">
<class name="class"/>
<component>

Up till now, the Xpath of "//component[@name="test"]/class[@name="class"]"
worked well to select the <class> tag.

Recently we added a namespace to the <component> tag:

<component xmlns=http://tempuri.org/test.xsd name="test">

Now, the Xpath no longer works from with in VB.NET. However, it is fine
when I check it via XMPSpy.

I tried adding a XMLNamespaceMan ger to the SelectSingleNod e, but to no
avail. any suggestions?

TIA

David

Nov 11 '05 #3

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

Similar topics

2
2971
by: kj | last post by:
Suppose I have some XML document that contains tags of the form <... xmlns:foo="http://www.bar.org/foo"> <... xmlns:foo="baz"> <... xmlns:frobozz="http://www.bar.org/foo"> What's the XPath expression to select the namespace nodes with prefix "foo"? And what's the XPath expression to select the
1
1774
by: alpha | last post by:
Hi Friends, When we need the xpath namespace as we can traverse the xml document using xmldocument object like using selectSingleNode or selectNodes methods. In system.xml.xpath namespace we have to use XPathNavigator , XPathExpression , XPathNodeIterator class to get the same result what we get it thru selectNodes ....and that too iterator can be traversed in forward direction only. Please tell me the usage of system.xml.xpath other than...
1
1605
by: Don | last post by:
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>
7
1996
by: John Bowman | last post by:
Hi All, I'm fairly new to XML, so I presume I'm doing something obviously dense here, but here it goes. Below is an XML file that was extracted from a test Windows Installer .MSP (patch) file using the MsiExtractPatchXMLData() method and directly written to disk as a test. On the surface, it seems to me to be valid XML since IE can load & display it. <MsiPatch xmlns="http://www.microsoft.com/msi/patch_applicability.xsd"...
18
7735
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr); System.out.println(xp.evaluate(new InputSource(new FileInputStream("a.xml"))));
3
4979
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml version="1.0" encoding="utf-8" ?> <thing xmlns="urn:thing-schema-v1"> <foo>foo thing</foo> <bar>bar thing</bar>
6
7299
by: J.Marsch | last post by:
I must be completely losing my mind. I have some code that writes to config files. It works great with app.config files, but fails miserably with web.config files. For the life of me, I cannot figure out what is going on here. I have taken it all the way back to just selecting the configuration node (top level node), and it fails! How can this line fail (returns null)??
14
17134
by: Mikhail Teterin | last post by:
Hello! What's would be the syntax for a query, which would allow me to get only the elements with non-empty text-nodes? For example, from: <a><b></b></a> <c/> <d><e>meow</e></d>
0
8888
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
9401
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...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8096
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
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
6011
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
4517
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...
1
3221
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
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.