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

trying to use xpath

Hello, not sure i am using xpath correctly. have the following trivial
xml.
<?:xml version="1.0" standalone="yes" ?>
<top attr="1">
content1
content2
<inner id="first" day="friday">
content3
</inner>
</top>

if i want the content of the tag "inner", do i need either of these or
something else?
/top/inner/child::text()
/top/inner/*[node()=text()]
and expect to be pointing at "content3".

thanks.

Jan 16 '07 #1
1 1761
wo************@yahoo.com wrote:
Hello, not sure i am using xpath correctly. have the following trivial
xml.
<?:xml version="1.0" standalone="yes" ?>
<top attr="1">
content1
content2
<inner id="first" day="friday">
content3
</inner>
</top>

if i want the content of the tag "inner", do i need either of these or
note yeu don't want the content of the tag inner (the content of the
start tag is "inner id="first" day="friday"" and the content of the end
tag is "/inner", you want the content of the element (it's best not to
confuse "tag" and "element" when working with xpath, as xpath has no
access to the tags.
something else?
/top/inner/child::text()
that's the same as
top/inner/text()
as child is the default axis, and selects the text node with content3
(and some white space) note that it's usially better to just use
/top/inner
as the string value of the element is all its text descendents. If you
explictly use text() then it will most likely fail if for example anyone
adds a comment
<inner>
<!-- here -->
content3
</inner>
as then the first text node is _just_ the white space before the comment
(and most xpath1 string functions only operate on the first node if mre
than one is selected)
/top/inner/*[node()=text()]
inner* selects all the element node children of inner but in your case
inner has no element children so this will be empty (even without the
filter). The filter [node()=text()] is true if any child node is equal
to any child text node. since the right hand side is a subset f the left
hand side this is always true if text() is non empty, ie if there is a
text node. so *[node()=text()] is *[text()] and selects all elements
that have text node children.

David
and expect to be pointing at "content3".

thanks.
Jan 16 '07 #2

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

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
5
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple...
11
by: hazz | last post by:
before I start filling up the first page of perhaps many pages of code with if/then or switch:case buckets, I wanted to step back and see if there is a better way... I will have a table with up to...
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);...
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: smachin1000 | last post by:
Hi All, In the sample schema & document below, I'd like the attribute "name" to be unique for all function elements under function_list. The tools I'm using (XML Spy and xmllint) all validate...
1
by: provowallis | last post by:
Hi all, I've been struggling with this for a while so I'm hoping that someone could point me in the right direction. Here's my problem: I'm trying to get the XPath for a given node in my...
2
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; In our program we will get an XPath statement such as: ${data}/SalesProject Where ${data} and ${series} both stand for a XPathNavigator so each is basically a specific node in a list of...
0
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...
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: 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
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
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
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...

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.