Extend JXPath to Generate Results in a Custom Data Model, Page 3
Using JXPath After Extension for a Custom Model
The code snippets in Figures 14 and 15 show how to create an XML container with a new parser using a new Key. Figure 14 shows the
getPackage() method from the model class MyModelPackageContainer and Fig 15 shows the
setXMLParser method, two methods for registering a custom parser and model.
Figure 15. MyModelPackageContainer Model Class
In Figure 14, the XML Parser (com.jxpath.setl.jw.sample.genericxmlparser.XMLSAXParser) object is registered to the JXPath framework by calling
In Figure 15, DocumentContainer is created with the model as
Note: You need to use same Key
(SAMPLE_PARSER) while registering a parser and model and while creating DocumentContainer.
This concludes the JXPath API explanation. The final section briefly discusses the data model used throughout the article.
What Have You Learned?
You now know the details involved in extending the JXPath API to derive a custom model while processing XPath language expressions over XML data. This way, you can extend the XPath engine, or even other XQuery engines that support extensions, to produce custom data models in different types of enterprise applications, as XML is used mostly as a means of data transfer. These applications could range from data integration to dynamic configuration.
Also, there many areas where you can improve from the example. You, for example, could have a more efficient algorithm for evaluating XPath expression. You could have a single layer of query for RDBMS and XML, an abstraction for querying that will hide the type of repository from which the data is fetched. So, the same query could be used seamlessly to interact with XML or a RDBMS.
Page 3 of 3