473,398 Members | 2,427 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,398 software developers and data experts.

XPath generation question

Hi;

We have a TreeView that represents an xml file (or it's schema is a more
accurate statement). We want to have a double click on a node in the tree
generate the XPath to get to that node.

For the full tree it's easy. We walk up the parents getting the name of each
node and put a / between each so we end up with /node1/node2 or
node1/node2/@attr1

Questions on this case:
1) should we start with /node1 or self::/node1?
2) if they click on the root should we use "self::" or "/"?

We also have cases where we have a tree from a SelectNodes() and then want
to handle a select from that. It seems to me that this case is no different -
that in one case we have an XmlDocument and the other an XmlNodeList. But an
XmlDocument is an XmlNode so is there a difference that matters between an
XmlNode and an XmlNodeList?

And if so, what should be the root of the xpath we create in this case?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
May 14 '07 #1
3 2606
* David Thielen wrote in microsoft.public.dotnet.xml:
>We have a TreeView that represents an xml file (or it's schema is a more
accurate statement). We want to have a double click on a node in the tree
generate the XPath to get to that node.

For the full tree it's easy. We walk up the parents getting the name of each
node and put a / between each so we end up with /node1/node2 or
node1/node2/@attr1

Questions on this case:
1) should we start with /node1 or self::/node1?
2) if they click on the root should we use "self::" or "/"?
I don't think there is a good reason to use the self axis in either case
and note that for the first question, your latter option is not valid
syntax.
>We also have cases where we have a tree from a SelectNodes() and then want
to handle a select from that. It seems to me that this case is no different -
that in one case we have an XmlDocument and the other an XmlNodeList. But an
XmlDocument is an XmlNode so is there a difference that matters between an
XmlNode and an XmlNodeList?
Well, an XmlNode is a single node, whereas an XmlNodeList is one or more
nodes, that seems an important difference but then I am not sure what
you are really asking here.
>And if so, what should be the root of the xpath we create in this case?
It might be impossible to create one. Consider this case, you have two
nodes in the node list like <a><b c=''/></aand <a><b c='' d=''/></a>,
in order to create a path that would only match the c attribute in the
former example, you would have to write it so that it won't match if a
'd' attribute also occurs on the element. This might become arbitrarily
complicated. Of course if the nodes are always from a single document,
you would only look at single nodes and there would be no difference.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
May 14 '07 #2
Hi;

Sorry - self::node().

We've found that self::node() works and "/" does not in some cases passing
it to an XPathNavigator for SelectNodes().

For your example we do not handle that case - what we handle is if they
wanted the d='abc' attribute to equal a given value such as 'abc'.

The issue is how should we build up the xpath for that query as we could be
querying against an XmlDocument or an XPathNavigator that is at a location
within the document?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm


"Bjoern Hoehrmann" wrote:
* David Thielen wrote in microsoft.public.dotnet.xml:
We have a TreeView that represents an xml file (or it's schema is a more
accurate statement). We want to have a double click on a node in the tree
generate the XPath to get to that node.

For the full tree it's easy. We walk up the parents getting the name of each
node and put a / between each so we end up with /node1/node2 or
node1/node2/@attr1

Questions on this case:
1) should we start with /node1 or self::/node1?
2) if they click on the root should we use "self::" or "/"?

I don't think there is a good reason to use the self axis in either case
and note that for the first question, your latter option is not valid
syntax.
We also have cases where we have a tree from a SelectNodes() and then want
to handle a select from that. It seems to me that this case is no different -
that in one case we have an XmlDocument and the other an XmlNodeList. But an
XmlDocument is an XmlNode so is there a difference that matters between an
XmlNode and an XmlNodeList?

Well, an XmlNode is a single node, whereas an XmlNodeList is one or more
nodes, that seems an important difference but then I am not sure what
you are really asking here.
And if so, what should be the root of the xpath we create in this case?

It might be impossible to create one. Consider this case, you have two
nodes in the node list like <a><b c=''/></aand <a><b c='' d=''/></a>,
in order to create a path that would only match the c attribute in the
former example, you would have to write it so that it won't match if a
'd' attribute also occurs on the element. This might become arbitrarily
complicated. Of course if the nodes are always from a single document,
you would only look at single nodes and there would be no difference.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
May 14 '07 #3
Hi Dave,

"/node1" in XPath means to search the node (node1) from the root.
"self::node1" in XPath means to search the node (node1) from the current
node.
If the current node is the root, there is no different between these two
XPath.
However, if the current node is not the root of XML, the result executed by
these XPath will be different.

For example:
/
-Node1
-Node2
-Node3
-Node4
-Node5

If the current node is / (root), you can get the node(Node1) by both
"/Node1" and "self::Node1".
But if the current node is the node(Node4), the XPath"/Node1" will work,
but the "self::node1" will return null. Additionally, if you want to a get
the node(Node5), you should use "self::node5" or "/node3/node4/node5". But
"/node5" will return NULL.
"self::node5" is a relative location path and "/node3/node4/node5" is an
absolute location path.
>1) should we start with /node1 or self::/node1?
I would like to start with "/node1", because it is the absolute location
path.
>2) if they click on the root should we use "self::" or "/"?
I think "/" should be the root.

http://www.w3schools.com/xpath/xpath_axes.asp
[XPath Axes]

Hope this helps.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 16 '07 #4

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

Similar topics

0
by: Bart Torbert | last post by:
I am using XMLSPY to create various XML Schemas. In text documents we have the XPATH mapped to various of our databases. Here is the problem----- How do I verify that I don't have any typos in...
2
by: Bart Torbert | last post by:
I am using XMLSPY to create various XML Schemas. In text documents we have the XPATH mapped to various of our databases. Here is the problem----- How do I verify that I don't have any typos in...
3
by: Stefan Behnel | last post by:
Hi! I need to generate source code (mainly Java) from a domain specific XML language, preferably from within a Python environment (since that's where the XML is generated). I tried using...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
2
by: adnw747 | last post by:
Hi All I am trying to generate an XPath expression based on a xml input. The generated XPath expression should then allow me find/detect that input xml code fragment is present within a larger...
4
by: ziggyware | last post by:
Hi All, I've been writing an XPath genration tool in .NET that has GREAT potential for business applications where exact XPaths are needed. Currently the tool is share ware however it can be...
0
by: ziggyware | last post by:
Hi All, I've been writing an XPath genration tool in .NET that has GREAT potential for business applications where exact XPaths are needed. Currently the tool is share ware however it can be...
2
by: luthriaajay | last post by:
I need some help to extract the LatestFillQuantity element value using XPATH. in Java. I am unable to extract the value of 10000. Please help as to what have I done wrong.? Help appreciated. ...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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,...
0
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...
0
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...
0
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,...

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.