How can I get the full XML path (as string) of a specific XmlNode ?
--
Thanks
Sharon 5 8330
Hi Sharon,
I'm not aware of anything out of the box that will give you this
information, but you can easily create the path using XmlNode.Parent
// given an XmlNode node
string s = node.Name;
while (node.ParentNode != null && node.ParentNode.NodeType !=
XmlNodeType.Document)
{
node = node.ParentNode;
s = node.Name + "/" + s;
}
On Mon, 20 Nov 2006 10:02:01 +0100, Sharon <Sh*****@newsgroups.nospam
wrote:
How can I get the full XML path (as string) of a specific XmlNode ?
--
Happy Coding!
Morten Wennevik [C# MVP]
This is one of those examples where I would recommend a StringBuilder over a
string for building the path, especially if this code is going to be called
many times.
Mark.
-- http://www.markdawson.org
"Morten Wennevik" wrote:
Hi Sharon,
I'm not aware of anything out of the box that will give you this
information, but you can easily create the path using XmlNode.Parent
// given an XmlNode node
string s = node.Name;
while (node.ParentNode != null && node.ParentNode.NodeType !=
XmlNodeType.Document)
{
node = node.ParentNode;
s = node.Name + "/" + s;
}
On Mon, 20 Nov 2006 10:02:01 +0100, Sharon <Sh*****@newsgroups.nospam>
wrote:
How can I get the full XML path (as string) of a specific XmlNode ?
--
Happy Coding!
Morten Wennevik [C# MVP]
Agreed; using .Insert() (or Push() each to a Stack<XmlNodeand Pop() it
afterwards, using .Append()).
Note, however, that this approach will not guarantee a usable path; for
instance, it doesn't distingusish between siblings, and doesn't allow for
namespaces, attribs, etc.
If you want this type of functionality, often a better approach is to have
an ID attribute or similar, so that you can uniquely reference the elements.
Marc
I don't see how a StringBuilder would improve this functionality. Unless
the xml is incredibly deep (>100 subnodes) there really won't be much, or
any, improvement. If you call the code many times you won't benefit from
a StringBuilder if you have to create the StringBuilder object each time.
On Mon, 20 Nov 2006 10:46:01 +0100, Mark R. Dawson
<Ma*********@discussions.microsoft.comwrote:
This is one of those examples where I would recommend a StringBuilder
over a
string for building the path, especially if this code is going to be
called
many times.
Mark.
--
Happy Coding!
Morten Wennevik [C# MVP]
This is one of those examples where I would recommend a StringBuilder over a
string for building the path, especially if this code is going to be called
many times.
Mark.
My guess is that in this case it will take *longer* if you use a
StringBuilder, because the new value is added at the *beginning*.
I imagine that adding at the front of the string will involve shifting
the old string around, which might take more time that the simple
string concatenation of the original solution.
But of course the best way to decide would be to time the various
solutions, using reasonable test-data (as others said, the node will
probably not be too deep).
Hans Kesting
>
"Morten Wennevik" wrote:
>Hi Sharon,
I'm not aware of anything out of the box that will give you this information, but you can easily create the path using XmlNode.Parent
// given an XmlNode node
string s = node.Name; while (node.ParentNode != null && node.ParentNode.NodeType != XmlNodeType.Document) { node = node.ParentNode; s = node.Name + "/" + s; }
On Mon, 20 Nov 2006 10:02:01 +0100, Sharon <Sh*****@newsgroups.nospam> wrote:
>>How can I get the full XML path (as string) of a specific XmlNode ? -- Happy Coding! Morten Wennevik [C# MVP] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JJ |
last post by:
Hi All,
I noticed that XmlNode and XpathNavigator are quite
similiar. XmlNode seems to navigate over an XML Doc and
so does XPathNav so when do I use XPathNavigator instead
of XmlNode?
...
|
by: The Clansman |
last post by:
Hi,
how do I get the path of an XML node?
I have:
Dim xmlNo As XmlNode = xml.SelectSingleNode("//Category")
I want to get the path of the xmlNo:
i.e.
|
by: Mahesh Devjibhai Dhola |
last post by:
Hi All,
I want to make a custom class in c#, which extends System.Xml.XmlNode class
of BCL.
Now in custom class, I have implement abstract methods of XmlNode class
also. Now when I am trying to...
|
by: Piculo |
last post by:
Hi,
I am working with XMLDocuments, and i go through it with XMLNode, and i want
know for each node the path in the XMlDocuments.
For instance for this XML i want get for each nodes the...
|
by: andrej |
last post by:
hi,
ich habe eine anwendung, welche ein xml document erstellt.
um festzustellen, ob ein element bereits vorhanden ist,
verwende ich die funktion
selectsinglenode( ....)
diese funktion...
|
by: Mahesh Devjibhai Dhola |
last post by:
Hi All,
I want to make a custom class in c#, which extends System.Xml.XmlNode class
of BCL.
Now in custom class, I have implement abstract methods of XmlNode class
also. Now when I am trying to...
|
by: Mae |
last post by:
Dear All,
I have a problem here, I'm using C# Webform calling a webservices. The
webservices return me a XMLnode, using this XMLnode I want to convert it to
dataset so I can bind to the...
|
by: Christian Rühl |
last post by:
heyho, guys! here's another question for you now:
i built an iterator to get all the nodes with a certain attribute in an
xml dom. it all looks like this (i'm using .NET framework 1.1)
...
|
by: Sharon |
last post by:
How can I get the full XML path (as string) of a specific XmlNode ?
--
Thanks
Sharon
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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...
| |