Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XPath And XML - A Simple How To

5 views
Skip to first unread message

gordon smith

unread,
Dec 20, 2012, 6:45:02 AM12/20/12
to
XPath is a W3C specification and also language which is used for finding information or data out of an XML file, it’s great for navigating through elements and attributes in a relatively easy method.

The easiest way to think of it is something just like the find and replace function in MS Word, however XPath is far more intricate than this with its own rules, syntax, structure as well as other such strict criteria, however the more familiar you become with XPath the better it will become, for me, it is now more natural.

Another point to consider is, how important is XPath. In the great scheme of things, you may almost certainly manage without it, in reality everything that that can be done with XPath when you use an XML document, you can actually attain without having XPath as well, hence in that sense it's not essential, however it's convenient.

For instance, working with XPath presents several benefits in terms of application development and dealing with XML documents, similar to speed, ease, effectiveness, productivity, simplicity etc etc

A very important difference to note is also that XPath is not really an XML language, though it may be closely linked with XML, it's actually a way for querying XML documents, but being related to XML, it’s also utilized in related specifications and languages like XSLT as well as in DOM implementations.

Remember that XML is nothing but a textual representation of associated nodes in a tree like framework. You will discover seven core nodes in XPath, these are Root, Element, Text, Attribute, Comment, Processing instruction and Namespace nodes.

If you are accustomed to programming syntax and taxonomy, these kind of terms will not be uncommon but also for those with no programming background, I will quickly elaborate.

The root node is the top or upper most part of an XML document, or in our tree analogy, it's the root from where the branches or elements spring from.

An element is a component of the data, by way of example in an xml file pertaining to customers, an element would be the first name or customer id. The element itself may contain text or attribute based information.

Commenting is also enabled in an XML document. These are a bit associated to XPath too, but a bit different in some aspects.

Along with a few of the visible features of XPath, you can also find some not very obvious, one example is, in XPath, the tree’s root node isn't the equal to its root element.

The tree’s root node contains the entire document, such as root element as well as comments and processing instructions that arise before the root element start tag or perhaps after the root element end tag.

Also, the XPath data models doesn’t actually have everything in the xml document, for example the XML declaration and the DTD. However, you will give a default value for your attributes which will be accepted by XPath.

Lastly, I ought to mention that in XPath, the xmlns attributes are not thought of as attribute nodes but instead namespace nodes, yet any non-namespace aware parser will look at them as an attribute.

A lot of info XPath can be obtained at W3C schools alternatively you can refer to this <a href="http://www.liquid-technologies.com/xpath-tutorial.aspx">XPath tutorial</a>.









0 new messages