Wednesday, October 23, 2013

Simplify XPath development by using XQuery

Most people have heard about XPath, it gives you a powerful syntax to navigate through elements and attributes in an XML document.  Most of the time XPath is used to transform one XML document to another(through XSLT). I always found the XPath syntax hard to read, especially if your expression start to get more complex.

That’s one of the reasons why I always tried to avoid using XPath and preferred writing a small C# program and use Linq to XML.

What I didn’t know is that XML had it’s own query language, XQuery, which offers you a similar more readable experience when walking through XML files. XQuery itself uses XPath underneath but it hides the complex expressions behind a nice and clean functional-style syntax.

From w3schools:


And here is a sample of the syntax:

1 comment:

Shruti Ramalingam said...
This comment has been removed by a blog administrator.