On Mon, Dec 12, 2011 at 4:50 PM, Tiberiu Tofan tibtof@gmail.com wrote:
Dear Christian, Thank's for your quick reply. I try to give you an example as I don't think my english is good enough to explain you otherwise: For a xml like:
<AAA> <BBB att1="bbb"> <CCC att1="ccc"/> <DDD att1="ddd"> <EEE att1="eee"/> </DDD> </BBB> </AAA> If i search for "ddd" i need the result to be: <AAA> <BBB att1="bbb"> <DDD att1="ddd"/> </BBB> </AAA>
Maybe this result can be achieved using xquery, I'm not sure as I don't know xquery well enough. I only tried using xpath, and with xquery I only scratched the surface, and as it wasn't leading me in the right direction and I was running out of time I had to use the solution that I've send you. From what I could figure out in Serializer.java, it seems to me that all the children of a result are serialized as well. I think it's worth mentioning that I don't know the structure of the xml in which i'm serching, and with XMLExtractSerializer I only use the xpath //*[@* contains text '%s'] and it gives me the result I need. If you think this can be achieved using XQuery please let me know and I'll allocate more time to look into it. Thank you for your time! Best regards, Tiberiu
On Mon, Dec 12, 2011 at 4:22 PM, Christian Grün <christian.gruen@gmail.com
wrote:
Dear Tiberiu Tofan,
thanks for your code snippet, always welcome! Before including new code, I'd like to ensure that it will represent added value for other users as well, so.. may I ask what your XMLExtractSerializer class is supposed to do? Maybe it can also be realized via XQuery?
Christian ___________________________
On Mon, Dec 12, 2011 at 3:15 PM, Tiberiu Tofan tibtof@gmail.com wrote:
Hi, I work on a project involving some large xml files that we need to
search
for specific attribute values, and I tried a solution based on BaseX database. After several hours of searching I found no way to serialize
the
answer as I needed (the elements that had the searched attribute value
and
all their parents). As I only had two days for a proof-of-concept I
made my
own serializer and now the result is as I expect it to be. As I find
these
feature to be useful I attached the source code and maybe you'll
consider to
include such a feature in a future release. Unfortunately I had to hack Serializer.java, as the node() method was final, and I suggest you at
least
to make the Serializer more configurable (eg. a properties file for the serialization options and the class to use and then reflection, splitting the node() method into several override-able sub-methods). On the other hand, maybe there is a way to obtain the result I needed
using
the existing features of basex, but as I told you I hadn't much time and this seemed to me the quickest solution.
Best Regards, Tiberiu Tofan
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Thank's for your quick reply. I try to give you an example as I don't think my english is good enough to explain you otherwise:
No problem. The following query will exclusively return the request node without its descendants:
let $xml := <AAA> <BBB att1="bbb"> <CCC att1="ccc"/> <DDD att1="ddd"> <EEE att1="eee"/> </DDD> </BBB> </AAA>
let $result := $xml//DDD return element { node-name($result) } { $result/@*}
Several approaches exist to also include the ancestor nodes in the result. One of them is to use the "transform" expression (copy/modify) and delete the irrelevant nodes from the result:
copy $xml := <AAA> <BBB att1="bbb"> <CCC att1="ccc"/> <DDD att1="ddd"> <EEE att1="eee"/> </DDD> </BBB> </AAA> modify delete node $xml//DDD/node() return $xml
If gets more difficult if you want to omit any other following and preceding nodes. This one here is one possible solution:
copy $xml := <AAA> <BBB att1="bbb"> <CCC att1="ccc"/> <DDD att1="ddd"> <EEE att1="eee"/> </DDD> </BBB> </AAA> modify ( let $result := $xml//DDD return ( delete node $result/child::node(), delete node $result/preceding::node(), delete node $result/following::node() ) ) return $xml
As a conclusion.. XQuery is very powerful! You might need some initial time to get to know it, but I’d claim it’s worth the trouble.
Hope this helps, Christian
basex-talk@mailman.uni-konstanz.de