last day (14 days later) » 

11:03 AM
2
Q: Use/include a value from another node

KamafeatherI have an XML file, like this: <area1> <settings> <setting name="to_include">value</setting> </settings> </area1> <area2> <settings> <setting name="where_to_include">?????</setting> </settings> </area2> I want to include the value of the setting node "to_include...

 
Obviously, you have not taken the time to familiarize yourself with those XML technologies. What you need depends on the language/environment you are using. For example, there are solutions for Python (e.g. lxml), Java, PHP; there is XQuery and XSLT. How about looking at an XSLT tutorial before asking here?
 
Unfortunately I don't have the time to familiarise with all the XML technologies, but I try to do it step by step, when new needs come out. I already have a solution at my language level (PHP) but I'm not allowed to perform changes on it. Cause of that I was wondering if there where a pure XML solution without altering the external environment. (i also added an XPointer example to my question)
 
Apologies, I slightly misunderstood your question. Are you sure XPointer and XLink are supported by your PHP solution?
And yes, xincludes pointing to the same file are not possible. How about writing a tiny XSLT transformation to do this?
 
My PHP solution relies on libxml and all the XML features are managed by that. So yes, all the parsing is performed correctly and it supports XPointer(s) (already used in the past).
By the way can you be more specific on what code should I use? I don't have experience with XSLT and don't get exactly what you mean I should do. By the way I already told that I'm not allowed to change anything on the PHP side, regarding the XML parsing/managing. Do you suggestion requires changes just to XML?
 
I think what you require is not possible without changing the application that manages the XML. If that's not possible, there's no point in explaining what you'd have to do. (Otherwise I'm glad to write an answer explaining how you'd do it with XSLT.)
 
11:03 AM
What I wonder about is that I can do it (with XInclude) pointing to another document, but it is not possible to refer to anything in the same document. This incapability looks like something weird to me and I believe that there should be a way to do it (at least referring the already parsed nodes).
If the xpointer could be used as node value, without relying on a XInclude tag; or if the XInclude could have a way to refer to itself...
 
This is getting too long for the comments section :-)
Well, in theory it would indeed be possible to xinclude from the same document when the part that should be included comes from a part of the XML that is parsed already
But in reality, applications do not allow for this - because it requires additional sophistication:
which is mainly keeping track of what is parsed already and compare it to the xincludes in the document
Also, the parse , or xinclude, or both will fail if the xinclude references a location in the same document that was not parsed yet
although XML parsers usually parse XML documents in document order, they are not strictly bound to add to an XML model (like DOM or XDM) in a linear fashion - as long as the final result is complete and accurate
so, the same xinclude might be possible in one situation, and impossible in another
all of this will perhaps change with the 3.0 round of X-Technologies
 
That's interesting. And I hope that 3.0 will be even more powerful.
I wonder then what could happen if I specify the URL of the file itself as 'href' attribute for an XInclude.
Would it be parsed (completely) as a different file, allowing so to refer any node in the document. Or it will have problems because of some XML check for not parsing the same file twice?
Or, even worse, will just fall into a loop cause at every parsing, for each XInclude, will start a new parse of the same file?
 
11:54 AM
Yes, that's an interesting question. You could find out by simply trying it. It gives you:
"FATAL ERROR: Recursive inclusion (same href/xpointer) of ..."
I have included the document the xinclude is written in like this: <xi:include href="test.html"/>
So, it is neither parsed as a different file nor does it fall into a neverending series of parses and inclusions
if an XML application would not recognize this, it would be very vulnerable to such a kind of attack
an attack where XML with an xinclude referencing the file itself is handed to a server application - which will break the server
 

last day (14 days later) »