473,569 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting the xpath for a specific node in a xmldocument

When you are "working" on a specific node from a XmlDocument instance, is it
possible to get the full xpath to this node?

Regards Paw
Nov 16 '05 #1
5 9547
PAW,

I can not understand what you looking for but does a portion of the code
below address answer your question?
private const String localURL =
"http://localhost/quickstart/howto/samples/Xml/QueryXmlDocumen tXPath/cs/book
s.xml";

public static void Main()
{
QueryXmlDocumen tXPathSample myQueryXmlDocum entXPathSample = new
QueryXmlDocumen tXPathSample();
myQueryXmlDocum entXPathSample. Run(localURL);
}

public void Run(String args)
{
Console.WriteLi ne("XPath Test started ...");

XPathDocument myXPathDocument = new XPathDocument(a rgs);
XPathNavigator myXPathNavigato r = myXPathDocument .CreateNavigato r();

// Get all the book prices
XPathQuery(myXP athNavigator, "descendant::bo ok/price");

// Get the ISBN of the last book
XPathQuery(myXP athNavigator, "bookstore/book[3]/@ISBN");
}

private void XPathQuery(XPat hNavigator myXPathNavigato r, String xpathexpr )
{
try
{
Console.WriteLi ne("XPath query: " + xpathexpr);

// Create a node interator to select nodes and move through them
(read-only)
XPathNodeIterat or myXPathNodeIter ator = myXPathNavigato r.Select
(xpathexpr);

while (myXPathNodeIte rator.MoveNext( ))
{
Console.WriteLi ne("<" + myXPathNodeIter ator.Current.Na me + "> "
+ myXPathNodeIter ator.Current.Va lue);
}
Console.WriteLi ne();
}
catch (Exception e)
{
Console.WriteLi ne ("Exception: {0}", e.ToString());
}
}

--------------------
From: "Paw Pedersen" <ne**@paws.dk >
Subject: Getting the xpath for a specific node in a xmldocument
Date: Sun, 31 Oct 2004 16:59:25 +0100
Lines: 6
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.181
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.181
Message-ID: <OO************ **@TK2MSFTNGP09 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
NNTP-Posting-Host: cpe.atm2-0-1121065.0x503eb aea.arcnxx10.cu stomer.tele.dk 80.62.186.234Path: cpmsftngxa10.ph x.gbl!TK2MSFTNG XA03.phx.gbl!TK 2MSFTNGP08.phx. gbl!TK2MSFTNGP0 9
.phx.gblXref: cpmsftngxa10.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:2835 01
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp

When you are "working" on a specific node from a XmlDocument instance, is itpossible to get the full xpath to this node?

Regards Paw


{\rtf1\ansi\ans icpg1252\deff0\ deflang1033{\fo nttbl{\f0\fnil\ fprq2\fcharset0
MS Sans Serif;}{\f1\fsw iss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.21.2500;}\ viewkind4\uc1\p ard\f0\fs20 Cheers,\par
\par
johnKn [MS-SDK]\par
\par
\par
\par
-Please do not send email directly to this alias. This alias is for \par
newsgroup purposes only\par
\par
-This posting is provided "AS IS" with no warranties, and confers no
rights.\par
\par
-To provide additional feedback about your community experience please send
\par
e-mail to: sd*****@microso ft.com\par
\f1\par
}

Nov 16 '05 #2
Why not write a function that walks the ancestors, checking each ancestor
the for the position in the collection and building a string from that
point?

That should be doable - then again, XPaths can be made i many different ways
but I guess you were looking for the fastest, right?

--
venlig hilsen / with regards
anders borum
--
Nov 16 '05 #3
Thank you,
I will try that. I had just hoped there was a build in function for that.

Regards Paw
"Anders Borum" <a@b.dk> wrote in message
news:Oy******** ******@TK2MSFTN GP11.phx.gbl...
Why not write a function that walks the ancestors, checking each ancestor
the for the position in the collection and building a string from that
point?

That should be doable - then again, XPaths can be made i many different ways but I guess you were looking for the fastest, right?

--
venlig hilsen / with regards
anders borum
--

Nov 16 '05 #4
Hello!

I haven't seen such functionality from the core .NET framework, but that
doesn't necessarily mean it's not there =o)

I would google a little around or just roll the code. It's a nice little
project actually! Let's see what you come up with =o)

--
venlig hilsen / with regards
anders borum
--
Nov 16 '05 #5
It worked fine looping with the Node.Parent approx.
Thanks.
Regards Paw

"Anders Borum" <a@b.dk> wrote in message
news:el******** *****@TK2MSFTNG P10.phx.gbl...
Hello!

I haven't seen such functionality from the core .NET framework, but that
doesn't necessarily mean it's not there =o)

I would google a little around or just roll the code. It's a nice little
project actually! Let's see what you come up with =o)

--
venlig hilsen / with regards
anders borum
--

Nov 16 '05 #6

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

Similar topics

2
6052
by: Neil Zanella | last post by:
Hello, I would like to know whether the mozilla web browser has built in support for searching XML documents via XPath expressions as with IE's xmlobject's and xmlDoc's function selectNodes() or similar. Thanks! Neil
2
1500
by: Steve Jorgensen | last post by:
Working with the DOM (specifically, the MSXML DOM), I'm wondering if there's an efficient way to check whether it would be matched by a given XPath expression. I've made it work to just run the XPath select on the document, looping through all the nodes returned, and seeing if one of those is the same as the node in question. If I need to...
4
5832
by: Andreas Håkansson | last post by:
I have a price of XML that looks like this <Root> <SomeNode> ..... </SomeNode> <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> ... </Signature> </Root>
1
1356
by: Mark Snelling | last post by:
Hi, I have a question regarding XPath and namespaces. I have a piece of XML... <Cred> <Meta> <Type xmlns='syncml:metinf'>syncml:auth-basic</Type> </Meta> <Data>QnJ1Y2UyOk9oQmVoYXZl</Data> </Cred>
4
8957
by: Gismo | last post by:
I have got file raport.rld which is an XML file generated by MS Reporting Services. The problem is: in this file are tags from two different namespaces xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefini tion" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"
2
3771
by: Bob | last post by:
I have sitemap like XML, of which every element has an attribute "url", e.g. <record menu_id="240" name="Countries and States" url="Countries.aspx"> <record2 page_id="54" url="CountriesEdit.aspx" /> <record3 page_id="27" url="Regions.aspx"> <record4 page_id="55" url="RegionsEdit.aspx" /> </record3> </record> I need to compare whether a...
3
6784
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer> </Root> I would like to retreive "\Root\Customer\Name" out of it. Something like:
4
4612
by: SkyHook | last post by:
1. Under the topic "Select Nodes Using XPath Navigation" it says: "All XmlNodeList objects are synchronized with the underlying document, therefore if you ... modify the value of a node, that node is updated in the document it came from." 2. Under the topic "XmlNode.SelectNodes Method (String)" it says: "The XmlNodeList should not be...
6
2002
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...
0
7703
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...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8132
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...
1
7678
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...
0
7982
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3656
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...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2116
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
1
1226
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.