There is a nice XPath API article on IBM developerworks site.
"XPath expressions are much easier to write than detailed Document Object Model (DOM) navigation code. When you need to extract information from an XML document, the quickest and simplest way is to embed an XPath expression inside your Java™ program. Java 5 introduces the javax.xml.xpath package, an XML object-model independent library for querying documents with XPath."
The Java XPath API
In Phylr, I am using XPath to get information from nexml, and put them into a lucene index. The tutorial if very helpful. I also found out that namespace makes things very complicated. If the XML has namespaces, then the NamespaceContext implementation has to use the same namespaces. But the NamespaceContext is acutally used to define namespaces in the xpaths. Therefore, they have to corresponds to the correct prefix used in the xpaths, not in the XML.
"XPath expressions are much easier to write than detailed Document Object Model (DOM) navigation code. When you need to extract information from an XML document, the quickest and simplest way is to embed an XPath expression inside your Java™ program. Java 5 introduces the javax.xml.xpath package, an XML object-model independent library for querying documents with XPath."
The Java XPath API
In Phylr, I am using XPath to get information from nexml, and put them into a lucene index. The tutorial if very helpful. I also found out that namespace makes things very complicated. If the XML has namespaces, then the NamespaceContext implementation has to use the same namespaces. But the NamespaceContext is acutally used to define namespaces in the xpaths. Therefore, they have to corresponds to the correct prefix used in the xpaths, not in the XML.
0 comments:
Post a Comment