473,387 Members | 1,579 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,387 software developers and data experts.

XPath Query w/ Namespace

I have the following XML document.

<?xml version="1.0" encoding="utf-16"?>
<xd:xmldiff version="1.0" srcDocHash="6067335156532207495" options="None"
fragments="no"
xmlns:xd="http://schemas.microsoft.com/xmltools/2002/xmldiff">
<xd:node match="1">
<xd:node match="1">
<xd:node match="4">
<xd:node match="3">
<xd:change match="@version">2</xd:change>
</xd:node>
</xd:node>
</xd:node>
</xd:node>
</xd:xmldiff>

If I take the prefixes off, the following query works as I would expect:
XmlNodeList rootNodes = changeDoc.SelectNodes("/xmldiff/node", nsmanager);

What does the code look like with the namespace prefix?

TIA.
Scot
Nov 12 '05 #1
1 1673
"Scot NS Curry" <sc****************@btopenworld.com> wrote in message news:uz**************@TK2MSFTNGP15.phx.gbl...
I have the following XML document. : : xmlns:xd="http://schemas.microsoft.com/xmltools/2002/xmldiff">
<xd:node match="1"> : : If I take the prefixes off, the following query works as I would expect:
XmlNodeList rootNodes = changeDoc.SelectNodes("/xmldiff/node", nsmanager);

What does the code look like with the namespace prefix?


Did you add the XmlDiff namespace URI to nsmanager? and
if so, what prefix did you give it? That prefix must appear in
the XPath expression, too.

XmlNamespaceManager nsManager =
new XmlNamespaceManager( changeDoc.NameTable);
nsManager.AddNamespace( "diff",
"http://schemas.microsoft.com/xmltools/2002/xmldiff");
XmlNodeList rootNodes = changeDoc.SelectNodes(
"/diff:xmldiff/diff:node", nsManager);

I use 'diff' to demonstrate that the choice of namespace prefix
added to the XmlNamespaceManager is irrelevant, it's the
namespace URI that counts.
Derek Harmon
Nov 12 '05 #2

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

Similar topics

1
by: Chris | last post by:
Hi all, I have recently started working with the new XML functionality in PHP5, but I am running into a few problems. Specifically, I am using an Xpath query to try and pull out the data in...
6
by: 0wl | last post by:
Hi, I am trying to get the value of child from xmlstr = """<p:root xmlns:p="http://tempuri.org/string"><p:child DataType="String">Hellpppp</p:child></p:root>""" using...
4
by: MarcoT77 | last post by:
Hi Teacher. I'm trying to get with Xpath the Product nodes in the following XML: <?xml version="1.0" encoding="utf-8"?> <PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"...
1
by: Robert | last post by:
I am having a problem selecting nodes using the XMLnodelist Selectnodes using XPATH when I use XML SPY is successfully queries but when is use VB.net it comes up with nothing. Here is my code ...
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: dc | last post by:
i have a xml file like this: <?xml version="1.0" encoding="utf-8"?> <validate xmlns="http://tempuri.org/fieldValidate.xsd"> <field name="Short Name" type="SN" length="10"> <requiredChar...
10
by: Michael C# | last post by:
OK, here's the deal. I have a small XML file that represents a small database table. I load it into a System.XML.XMLDocument. So far so good. I run an XPath query against it to retrieve all the...
18
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);...
3
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...
3
by: 0to60 | last post by:
Please help! I'm using the following code to get an XML doc: string str = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=12345&city=addison"; System.Net.HttpWebRequest request =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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,...

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.