Tuesday 18 December 2012

Just what Is XPath?

XPath is a W3C standard and language which can be used to find info or data from an XML file, it’s very good for navigating through elements and attributes in a simple manner.

The best way to look at it is something such as find and replace function in MS Word, however XPath is a lot more advanced than this with its own rules, syntax, structure as well as other such rigorous criteria, nevertheless the more familiar you become with XPath the easier it will get, for me, these days it is more second nature.

The other point to consider is, just how important is XPath. In the grand scheme of things, you may almost certainly cope without it, in reality whatever that you can do with XPath when working with an XML document, you are able to realize without XPath too, and so in that sense it's not essential, it can be handy.

As an example, utilizing XPath presents several benefits with regards to application development and dealing with XML documents, like speed, ease, effectiveness, productivity, simplicity etc etc

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

Don't forget that XML is nothing at all but a textual representation of associated nodes in a tree like design. There are seven core nodes in XPath, these are Root, Element, Text, Attribute, Comment, Processing instruction and Namespace nodes.

If you're accustomed to programming syntax and taxonomy, these kind of terms will not be uncommon however for those with no programming background, I am going to quickly elaborate.

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

An element is a component of the data, by way of example in an xml file concerning customers, an element may just be the first name or customer id. The element alone can easily contain text or attribute based information.

Commenting is also enabled in an XML document. These are a bit synonymous to XPath as well, but a bit distinctive in some aspects.

And many of the apparent features of XPath, you can also find quite a few not so apparent, such as, in XPath, the tree’s root node is not the same as its root element.

The tree’s root node has the entire document, including the root element and also comments and processing instructions that occur prior to the root element start tag or following the root element end tag.

Also, the XPath data models doesn’t have everything in the xml document, for instance the XML declaration and the DTD. Nevertheless, you may give a default value for your attributes and this will be recognized by XPath.

Last of all, I should point out that in XPath, the xmlns attributes aren't considered attribute nodes but instead namespace nodes, yet any non-namespace aware parser will view them as an attribute.

More info on XPath can be found at W3C schools or you can consider this XPath tutorial.













































Monday 10 December 2012

Just What Exactly Is XPath

XPath is a query language employed in XML to query and also pick nodes from an XML document. The truth is, you may even work with it to determine ideals, like strings, numbers and Bolean values) in the content of any XML document.

It works by pointing to data within a XML file which are nodes, it may also point to nodes and carry out simple mathematics measurements, in reality XPath is simply as vibrant as XML and you could select nodes depending on many conditions similar to mathematics comparisons.

XPath is incredibly versatile therefore you can use it with some other standards beyond XML, for example XSLT and XPointer. Using XSLT there is the capacity to develop one XML document to the back of some other XML document, and also make a XHTML document which may be read and looked at by the bare human eye.

But how does XPath work exactly? To be really exact, it works by pointing to the XML dataset, in other words you have to access the DOM and not really the actual characters which might be in the XML tag. So for this reason, so that you can process with XPath, you'll need a document format that can establish a DOM or similar dataset, such as XML or JSON.

Even more importantly, you may use a location path syntax, which you'll do in a few methods. An individual '/' at the beginning of an area path presents the document node, the only child of which is the root element. If a location path commences with a '/' (thus from the document node), it is an absolute location path, otherwise it's a relative location path.

When working with XPath to make your search queries, you can use a number of parameters or queries.

One such parameter is Predicate (the part that is inside the square brackets), that can be used to filter results and might include any expression. In cases where the result is not empty, the considered to be true, and if it is empty then it is deemed false. If the result is a numeric value, that number value represents the proximity of the position of the node

From the proximity position, you have a forward and reverse axis. The forward axis is one where all the nodes come after the context node, like child etc. The Reverse axis is the opposite, i.e. the nodes arrive prior to the context node, like parent etc.

There are also numerous important functions that are utilized in Xpath, these include position() and last(). Last() will return the last position inside your current node selection and position() will return the position of a node in your selection.

Finally, XPath also offers full assistance for namespaces, the names are indicated in the same manner as in XML nonetheless the prefix itself is bound externally to the namespace URI, which means it should be done by the external application or specification that it is being used in.

A lot of XPath can be found at W3C schools you can also refer to this XPath tutorial.