|
XML Home
XML Tutorial About XML XML Viewers XML Editors XML Documents XML Syntax XML Elements XML Attributes XML with CSS XML with XSL XML Namespace XML Local Namespace XML Default Namespace XML Entities XML Creating Entities XML CDATA DTDDTD IntroductionDTD DOCTYPE DTD Internal DTD External DTD Combined DTD FPI DTD Elements DTD Element Operators DTD Attributes DTD Attribute Default Values DTD Attribute Types DTD General Entities DTD Parameter Entities DTD Embedded Images XSLTXSLT IntroductionXSLT Example XSLT Syntax XSLT <template> XSLT <apply-templates> XSLT <value-of> XSLT <for-each> XSLT <sort> XSLT <if> XSLT <choose> XPathXPath IntroductionXPath Location Path XPath Location Path - Absolute XPath Location Path - Relative XPath Attributes XPath Axis XPath Node Test XPath Predicate XPath Node Set XPath Comparison Operators XPath Boolean Operators XPath Number Operators XPath String Functions Tutorial Summary XHTML Tutorial AJAX Tutorial FREE Hosting!With every domain name you register with ZappyHost, you get FREE hosting.$1.99 Domain NamesWith every new non-domain purchase thru ZappyHost, you get a domain name for only $1.99. |
XPath Location Path - RelativeNow that we've looked at absolute location paths, let's look at relative location paths. A relative location path is one where the path starts from the node of your choosing - it doesn't need to start from the root node. This can reduce the amount of code you need to write - especially if you need to select many nodes that share the same name. Example of a Relative Location PathConsider the following XML document:
If we wanted to select the "title" node of all albums, we could use the following (relative) location path:
The ResultThis single line of code has exactly the same result as the example in the previous lesson. The only difference is that, in the previous lesson, we needed 3 lines of code to provide the same result. So to just to make sure you understand what this line of code is doing, it is selecting all title nodes within our XML document. We don't need to provide the full path - just the name of the node we need to work with. This makes our like easier and keeps our code nice and clean.
ChildrenWe can also select a node's children using relative location paths. Example 1 - Selecting the two children of the "rock" node ("title" and "artist"). The context node is "rock", because that's where our relative path starts:
Example 2 - Using a wildcard to select all children of the "rock" node. This (single line of code) has the same result as the above two lines of code. Further, if another node was added to the XML document under the "rock" node, it would be automatically included using the wildcard:
About the WildcardIf you don't know what I mean by "wildcard", it is represented by the asterisk ( Wildcards don't have to appear at the end of a location path - they can also appear in the middle of a location path. We aren't limited to just one either - we could use as many as we like within a location path. Enjoy this website?
Oh, and thank you for supporting Quackit! |
Need Content for your Website?Get unique, quality digital content for your website. You can even earn money by reselling it!Includes:
|