You can use entities/entity references for referencing and reusing content at multiple places, within or across files.
An XML file declaring and using an entity looks like this:
<!DOCTYPE doc [
<!ENTITY myent "<x>Text content of myent</x>">
]>
<doc>
&myent;
&myent;
</doc>
This XML file is handled as if
<doc>
<x>Text content of myent</x>
<x>Text content of myent</x>
</doc>
had been specified. That is, the entity reference &myent;
is substituted by its replacement text <x>Text content of myent</x>
.
This works also with replacement text stored in an external file (called an external entity). Assuming the file above is stored as doc.xml
, you can reference it from another XML file like this:
<!DOCTYPE otherdoc [
<!ENTITY doc SYSTEM "doc.xml">
]>
<otherdoc>
&doc;
</otherdoc>
and an XML parser will treat it as if
<otherdoc>
<doc>
<x>Text content of myent</x>
<x>Text content of myent</x>
</doc>
</otherdoc>
had been specified.
Using entities, you can organize common XML content without redundancy within or accross files. Hope that helps.
Edit: note that you have to adapt the DOCTYPE - it must match the document element of your XML
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…