Hi Huib,
Thanx for the reply.
I’ve seen this kind of solution before on the internet but this does not work in my case.
I don’t have a single @ref-attribute in $node-element. Instead I have several ref-child-elements within a $node-element. (that is what a meant with linear versus iterative)
In that case I would have an iteration through the ref-child-elements within my function. So there will be an iteration of recursive calls.
But every time I come back from a recursive call my ref-collection won’t be updated with the processed $nodes from this call but will be reset to its original value.
This because of the declarative nature of the XML-tools.
So now I started programming in JAVA in eclipse and stored my XML-files in a BaseX-database.
I can connect to the database but I was wondering what the best approach would be from there.
Any suggestions would be welcome.
Van: Huib Verweij [mailto:hhv@home.nl] Verzonden: dinsdag 17 juli 2012 20:33 Aan: Rob CC: basex-talk@mailman.uni-konstanz.de Onderwerp: Re: [basex-talk] Question concerning querying cyclic network xml-structure.
Hi Rob,
I think XQuery and XSLT are very much capable of handling your example. If I understand it correctly, I do not know what linear or iterative recursion is.
In fact I programmed something similar to the algorithm you describe in XQuery recently. I was processing nodes from the BaseX database though, not XML files. Starting with the first node and an empty sequence as the two arguments to the function I process only references that are NOT in the sequence.
declare function local:refs($node, $refs) {
if ($node/@ref)
then
if (empty(index-of($refs, $node/@ref))
then let $processedNode := <do something with $node>
return local:refs($processedNode, (@ref, $refs))
else ...
else <process all children of $node>
}
Well, it looked something like that. You get the idea I hope. Just add every processed reference to $refs and check that the current @ref is not in $refs before you process it.
If storing your XML inside BaseX is not an option you might try out Nux (http://acs.lbl.gov/software/nux/), I have used it successfully to process XML files in the past, simply using the fire-xquery command line tool.
Regards,
Huib Verweij.
Verstuurd vanaf mijn iPad
Op 17 jul. 2012 om 15:01 heeft Rob r.stapper@home.nl het volgende geschreven:
Hi,
Can you please help me solving a challenge I have with a specific type XML-query?
I’ve a bunch of XML-files that are referencing each other.
So, a XML-file can reference to multiple XML-files and a XML-file can be referenced to by multiple XML-files. This whole reference-structure could be cyclic.
Actually an m:n relationship between XML-files with possible cyclic structure.
The standard solution would be to build a recursive-routine for processing an XML-file that, before actually processing the XML-file, checks in some way, for example with some sort of “file-in-process”-buffer, if the XML-file isn’t already being processed. If not store the name in this buffer, processes the XML-file and initiate the recursive routine for the referenced XML-files.
A structure like this (not real code (at all)):
==============================================================
INSTANTIATE Guard FROM COLLECTION
PROCESS-RECURSIVELY( XML-fileName) {
PROCESS( XML-fileName)
ITERATE Called-XML-file THROUGH XML-file//call-ELEMENT {
IF NOT ( Guard.EXISTS( Called-XML-file.NAME) {
Guard.ADD( Called-XML-file.NAME)
PROCESS-RESURSIVELY(Called-XML-file.NAME)
}
}
}
PROCESS-RESURSIVELY(“start-file”)
=============================================================
I found out that, but I could be mistaken, that the standard W3C-XML-tooling (XPATH, XQUERY, XLST) can’t handle this situation because of their declarative nature.
Recursiveness is possible with these tools but only in a linear way not in an iterative way.
That is why I’m looking for alternatives. Hopefully BaseX can help me out here.
I’ve BaseX and the JAVA-examples in eclipse running.
I’m b.t.w. nor a JAVA- nor an eclipse-expert so it was a bit of a struggle, but I managed.
My question: What is the best way to approach this challenge?
Can you give me some tips?
Kind regards,
Rob Stapper
Meine frage ist in English weil mein Deutsch nicht so gut is wie mein Englisch. Enschuldigung dafür. ;-)
_____
I am using the Free version of SPAMfighter http://www.spamfighter.com/len . SPAMfighter has removed 501 of my spam emails to date.
Do you have a slow PC? http://www.spamfighter.com/SLOW-PCfighter?cid=sigen Try free scan!
_______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk