BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
XQuery
XQuery Primary Expressions
Programming with XQuery classes
XQuery Demo namespace
XQuery Demo
What is XQuery and ASP.NET?
What is XQuery?
Why do I need XQuery when I already have XSLT/XPath?
XQuery 1.0 syntax types and some query examples.
How to use XQuery in ASP.NET
Learn XQuery 1.0 fundamentals
<< XmlSerializer
XSLT >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :202

 

Path Expressions

Path Expressions

This type of expression is used to locate nodes in a given tree or XML document.

You can use either relative or absolute (rooted) path expressions. Relative path expressions are used in context with the current node.

If you query a document, you should always use the document() function, which takes the documents name as its parameter.

Worksheet 1: Path Expression examples

Expression:

Example(s):

Path Expressions

1. document("xqt")

In this first example (which is by default shown when the application is run), the output is simply the same as your input XML. The document() function is used here to access the XML source as an XQuery navigator collection, in which each navigator has its own name – in this case, ‘xqt’. We'll see more of this when we come to look at the code, later on in this tutorial.

2. <root> { document("xqt")//title } </root>

which in this case is basically the same as

<root>

{ document("xqt")/root/tutorials/tutorial/title }

</root>

The output shown is:

<?xml version="1.0"?>

<root>

  <title>Introduction to XQuery</title>

  <title>XQuery's Syntax</title>

  <title>XQuery: Advanced Tricks</title>

</root>

Here, the path expression selects every title that can be found in the XML source. From this xquery, a screenshot is added after the next third example.

3. <root>

     { document("xqt")//title/text() }

   </root>

Here, the input xquery is neatly formatted, but that does not influence the output in any way – it is just for readability and easy writing.

The output shown is:

<?xml version="1.0"?>

<root>Introduction to XQueryXQuery's

SyntaxXQuery: Advanced Tricks</root>

In this case, the values of the four found titles are concatenated into one string here (actually on one line) because the path expression contains text(). Note that whitespace or other special characters (like returns and linefeeds) located outside the element nodes are not outputted by the XSL processor.

To show one more screenshot of XQueryTester in action, the output of the second example is shown on the next screenshot:

 

Fig. 7: Screenshot of a working example with its output

You can see that the output is nicely colored and indented, just like IE does. This cool look is due to Jason Patterson's stylesheet.


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

An immediate job opportunity as a B
Software Developers Needed in Charl
Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C

View all Jobs (Add yours)
View all CV (Add yours)



answering service
fax server
swimming pool contractor
halloween mask
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP