Let assume I have a set of arbitrary XML's that I would like to embed into each other recursively. Is there any technology or framework helping with this? I am looking for something adding, removing and sea开发者_开发技巧rching XML's within XML's.
EDIT
Someone removed the recursion tag from my question. I guess I am not making myself clear. Let's imagine XML's represent data structures instances referring each other. Is there a technology/framework handling this?
EDIT II
Someone claims I am not talking about recursion, but about circular references at best. I am not excluding the possibility of having one data structure referencing itself (by instance or by definition, it does not matter). I DO mean recursive as in fractal so to speak, so please stop removing my tag.
No, not out of the box in standard XML. Basically you need to have a mechanism of recording linkage between elements in the final XML document, and then have a savvy marshalling and demarshalling tech to handle the references. This is an object serialization to XML issue, effectively.
Without it, for example, if you were to try and save a circular list, you'd end up having an infinite loop as the tail element returns to the head element and keeps writing. References fix that issue for you.
I believe XStream will do this for you out of the box (if you're in Java, but you don't mention that).
The correct way of embedding one xml document in another is to use namespaces to differentiate the content.
Sometimes people entity-encode the inner xml and embed it as a string, but that's a really bad thing to do. Don't do it.
Recursion in XML is handled with pairing id and idref attributes. If you want one part of an XML document to refer to another part, place an id attribute on the part you're referring to, and an idref attribute on the referrer.
As far as I know no parsers will traverse these attributes automatically, you need to do it manually.
What about XInclude? E.g. XOM and Xerces support this extension.
精彩评论