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

Help me with XPATH expression

Hi folks,

I am new to XML. I came across the following location path expressions:

(i) /*/*

(ii) /quotelist/quotation

can anyone explain me the nodeset for the above two path expressions
relating to the following XML document:

<quotelist>
<quotation style="wise" id="q1">
<textExpect nothing; be ready for everything. </text>
<sourceSamurai Chant </source>
</quotation>

<quotation style="political" id="q2">
<textIf one morning I walked on top of the water across the
Potomac
River, teh headline that afternoon would read "President
can't Swim".</text>
<sourceXYZ </source>
</quotation>
<!-- This is a comment -->
<quotation style="silly" id="q3">
<textWhat if the hokey-pokey IS what it's all about?
</text>

</quotation>

</quotelist>

Thanks in anticipation.

Regards,
Asrar

Oct 1 '06 #1
2 1248
This is pretty darned basic. If this is the level of information you
need, I *REALLY* recommend that you read an XPath tutorial or two,
because otherwise we're going to wind up spoon-feeding you the
equivalent of one. One good collection of tutorials and articles can be
found at
http://www.ibm.com/xml

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Oct 1 '06 #2
aj*****@googlemail.com wrote:
Hi folks,

I am new to XML. I came across the following location path expressions:

(i) /*/*

(ii) /quotelist/quotation

can anyone explain me the nodeset for the above two path expressions
Assuming this is XPath, then

(i) means "any element which is a child of [any] root element".
In your sample document, it will return a nodeset of three
quotation elements.

(ii) means "all quotation elements which are children of the
quotelist root element". The effect on your sample document
is identical to (i).

According to whatever DTD or schema you use, there may of course be
other element types which are permitted within quotelist. These will
be included in the nodeset by (i) but not by (ii).

Equally, your application may allow other element types to be the
root element of different subtypes of document. In that case, (i)
may be more appropriate than (ii) in some circumstances. For example,
if you output a document consisting of a single quotation, eg:

<quotation style="wise" id="q1">
<textExpect nothing; be ready for everything. </text>
<sourceSamurai Chant </source>
</quotation>

then (i) will return a nodeset consisting of a text element and a source
element, but (ii) will return an empty nodeset.

As a matter of style and efficiency, you should avoid using leading and
trailing spaces in element types containing PCDATA or mixed content, in
case later processing systems are unaware of it (the source above, for
example, is NOT equal to "Samurai Chant" but " Samurai Chant " with the
extra spaces.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
relating to the following XML document:

<quotelist>
<quotation style="wise" id="q1">
<textExpect nothing; be ready for everything. </text>
<sourceSamurai Chant </source>
</quotation>

<quotation style="political" id="q2">
<textIf one morning I walked on top of the water across the
Potomac
River, teh headline that afternoon would read "President
can't Swim".</text>
<sourceXYZ </source>
</quotation>
<!-- This is a comment -->
<quotation style="silly" id="q3">
<textWhat if the hokey-pokey IS what it's all about?
</text>

</quotation>

</quotelist>

Thanks in anticipation.

Regards,
Asrar
Oct 1 '06 #3

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

Similar topics

0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
3
by: gimme_this_gimme_that | last post by:
I once downloaded a shareware program that allowed you to open an xml file, click on a text or an attribute, an then see the xpath expression that would fetch that data. The program didn't...
4
by: Rune | last post by:
I have two queries that appear to be exactly the same, but one of them returns null while the other one returns a valid result! Can anyone provide an explanation to why this is so? Below is an...
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: AGB | last post by:
Hi all, I have the following simple XML file. I would like to load all the values in the Name nodes into a drop-down list box: <?xml version="1.0" encoding="utf-8" ?> <OutlineCodeNames>...
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...
6
by: Chua Wen Ching | last post by:
Hi there, I had this xml file with me (not yet consider implementing xml namespaces yet). <?xml version='1.0'?> <Object> <Windows> <EID>1</EID> <EDesc>Error 1</EDesc> </Windows>
2
by: Paul | last post by:
I'd like to write an XPath expression that gets all nodes with a given local-name, say 'Customer', within a given namespace. From a prior response I got the following to get nodes with a specific...
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: arunairs | last post by:
Hi, Is there a way of validating and XPath? In this case , I am accepting an XPath from the user and I need to validate the XPath syntax. Is there a regular expression available that anyone can...
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: 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...
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
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
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?
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
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...

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.