Reusing an XML Element from Another File

Is it possible to use an XML element from another file in another XML?
For example, instead of:

<document>
   <a><!-- huge content --></a>
   <b/>
</document>

I would like to:

<document>
    <a ref="aDef"/>
    <b/>
</document>

Where defined in native XML and used if necessary. I would like this to be done by the parser and be transparent to the application, the application will not be able to find out if this element is a link or a copy.
How can i do this?

+3
source share
2 answers

This is what the xinclude W3C standard means . Similar to the approach of external objects (as in the answer above), you can encode content that will be included in a separate file, for example, for example. (Frag.xml):

<a><!-- huge content --></a>

XML xinclude :

<document>
  <xi:include href="frag.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
  <b/>
</document>

XML-, xinclude (, Xerces http://xerces.apache.org/), xinclude , . @href URI, (, href="frag.xml#fragment1).

URI @href, xinclude @xpointer. XPointer XPointer, . () XSLT: XIPr (http://dret.net/projects/xipr/).

+3

:

XML (frag.xml):

<a><!-- huge content --></a>

XML:

<!DOCTYPE document [
<!ENTITY aDef SYSTEM "frag.xml">
]>
<document>
   &aDef;
   <b/>
</document>
+2

Source: https://habr.com/ru/post/1756040/


All Articles