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.
SPAMfighter has removed 501 of my spam emails to date.

Do you have a slow PC? Try free scan!
_______________________________________________
BaseX-Talk mailing list
BaseX-Talk@mailman.uni-konstanz.de
https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk