views:

337

answers:

1

I'm trying to see how libxml implements XPath support, so it made sense to me to test using xmllint. However, the obvious option, --pattern, is somewhat obscure, and I ended up using something like the following:

test.xml: <foo><bar/><bar/></foo>

> xmllint --shell test.xml
/  > dir /foo
ELEMENT foo
/  > dir /foo/*
ELEMENT bar
ELEMENT bar

This seems to work, and that's great, but I'm still curious. What is xmllint's --pattern option for, and how does it work?

Provide an example for full credit. =)

A: 

From the xmllint(1) man page:

   --pattern PATTERNVALUE
          Used to exercise the pattern recognition engine, which can be
          used with the reader interface to the parser. It allows to
          select some nodes in the document based on an XPath (subset)
          expression. Used for debugging.

It only understands a subset of XPath and its intention is to aid debugging. The library that does understand XPath fully is libxslt(3) and its command-line tool xsltproc(1).

The ``pattern'' module in libxml "allows to compile and test pattern expressions for nodes either in a tree or based on a parser state" and its documentation lives here: http://xmlsoft.org/html/libxml-pattern.html

Ari.

iter
I also can read the xmllint man page! However, it doesn't tell me what I want to know. Using xmllint --pattern always seems to spit back the entire doc, which is why I'm asking the question in the first place. Like I said, "provide an example for full credit".
Matthew Lowe