Re: [bdbxml] using DBXML API to query an Xml Doc
George Feinberg <[email protected]>
| Newsgroups | gmane.comp.db.dbxml.general |
|---|---|
| Message-ID | <[email protected]> |
> I implemented a system that in order to render some xml files i
> used Xquery to get docs from the database and after follow on
> queries to get the specific values from the docs so as to render as
> needed.
>
>
>
> I wanted to make my system distributed by having the part of
> getting the doc from the database in the one side and the part of
> doing the follow on queries in the other side .I separated the
> system having the Xml Server in the one side and the application
> that uses the Xml files of the server. I did it using a web
> service architecture .
>
>
>
> I was asking via a soap msg the appropriate xml doc .After I used
> Berkeley DBXML API to convert this (String)Xml Doc to an
> XmlDocument , after I was making a new XmlValue and finally I was
> making my Query.
>
>
>
> XmlManager theMgr = new XmlManager();
>
> XmlDocument Doc=theMgr.createDocument();
>
> Doc.setContent(“"<aDoc><title>doc1</title><color>green</
> color></aDoc> ”);
>
> XmlValue value=new XmlValue(Doc);
>
> XmlQueryContext Context = theMgr.createQueryContext();
>
> XmlQueryExpression Expression = theMgr.prepare(" //color ”,
> Context);
>
> XmlResults Results = Expression.execute(value, Context);
>
>
>
> My question is if using DBXML API to query over an Xml doc without
> it being in the database is efficient ????
Using the XQuery functions built into BDB XML without using the
database portion
works well, and is fully supported.
I'd make two suggestions for this, based on the above code.
1. You should instantiate a single XmlManager object, and keep it
around for
the lifetime of your application. It can be safely shared among
threads.
2. Also, it is well worth creating XmlQueryExpression objects using
the XmlManager::prepare() method, and keeping them around as well
(perhaps in an STL map, or something similar).
They can also be safely shared among threads (do NOT share
XmlQueryContext objects, however).
> Instead of it I could use Xalan engine .
I can't compare to Xalan. I can make a couple of comments based
on the implementation in BDB XML.
1. Parsing/DOM. In BDB XML, in queries such as yours, against
transient
documents, the "DOM" tree created is done lazily (it doesn't use the
Xerces DOM parser). That is, it creates nodes for elements, but avoids
constructing/destroying attribute and text nodes until required by
the query.
This means better memory management and less memory used and more
efficient code than if BDB XML used the Xerces DOM implementation.
2. Querying. Because it controls the DOM being queried, BDB XML adds
(and will be adding more) some methods that traverse the tree more
efficiently
in XQuery than can be done if simply working on top of a Xerces DOM
layer.
In other words, it is the intent of BDB XML to be as efficient as
possible even
for querying of documents that do not appear in the database.
This is important because the same code is used when querying
documents stored in a wholedocument container.
> I decided to use DBXML API instead of Xalan engine as two queries
> over my Doc are enough to render my XmlDoc.
>
> Any comparisons between Xalan and DBXML API for rendering Xml docs
> are accepted .
Yes, please share.
Regards,
George