<p>I am creating an installer in IzPack. It is quite large, and I have broken up my XML files appropriately using &lt;xinclude&gt; and &lt;xfragment&gt; tags. Unfortunately, IzPack does not combine them together when you build your installer. This requires you to package the files with the installer, which just won't work. </p>

<p>I was about to start writing a tool in Java to load the XML files and combine them, but I don't want to go reinventing the wheel. </p>

<p>Do the Java XML libraries provide native handling of xinclude? A google didn't seem to turn up much. </p>

<p>Not a big deal if I have to write this myself, just wanted to check with you guys. Thanks.</p>

<p>Format of XML for example purposes:
File1.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?&gt;
&lt;installation version="1.0"&gt;
&lt;packs&gt;      
    &lt;pack name="Transaction Service" id="Transaction Service" required="no" &gt;
        &lt;xinclude href="example/File2.xml" /&gt;
    &lt;/pack&gt;
&lt;/packs&gt;
</code></pre>

<p>File2.xml</p>

<pre><code>&lt;xfragment&gt;
    &lt;file src="..." /&gt;
&lt;/xfragment&gt;
</code></pre>

<p>File2 does not need the standard XML header. The xml file is parsed at build time, because the resources it specifies are included in the installer. What isn't included is the actual XML information (order to write the files, where to put them etc.)</p>

<p>What I am looking to have produced:</p>

<pre><code>&lt;?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?&gt;
&lt;installation version="1.0"&gt;
&lt;packs&gt;      
    &lt;pack name="Transaction Service" id="Transaction Service" required="no" &gt;
        &lt;file src="..." /&gt;
    &lt;/pack&gt;
&lt;/packs&gt;
</code></pre>

<p>Thanks, I am going to start whipping it together in Java now, but hopefully someone has a simple answer. </p>

<p>Tim Reynolds</p>

[{'answer_id': 73306, 'author': 'Paul de Vrieze', 'author_id': 4100, 'author_profile': 'https://Stackoverflow.com/users/4100', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m not sure if java supports automatic xinclude. But you will have to use namespaces to make it work. So don\'t use <code>&lt;xinclude ....&gt;</code>, but use: </p>\n\n<pre><code>&lt;xi:xinclude xmlns:xi="http://www.w3.org/2001/XInclude" href="example/File2.xml" /&gt;\n</code></pre>\n\n<p>Normally the included file should still contain the xml header as well. There is no requirement for it to e.g. have the same encoding.</p>\n'}, {'answer_id': 74275, 'author': 'Brian Agnew', 'author_id': 12960, 'author_profile': 'https://Stackoverflow.com/users/12960', 'pm_score': 1, 'selected': False, 'text': '<p>If you can\'t get xinclude to work and you\'re using Ant, I\'d recommend <a href="http://www.oopsconsultancy.com/software/xmltask" rel="nofollow noreferrer">XMLTask</a>, which is a plugin task for Ant. It\'ll do lots of clever stuff, including the one thing you\'re interested in - constructing a XML file out of fragments.</p>\n\n<p>e.g.</p>\n\n<pre><code>&lt;xmltask source="templatefile.xml" dest="finalfile.xml"&gt;\n  &lt;insert path="/packs/pack[1]" position="under" file="pack1.xml"/&gt;\n&lt;/xmltask&gt;\n</code></pre>\n\n<p>(warning-  the above is done from memory so please consult the documentation!).</p>\n\n<p>Note that in the above, the file <em>pack1.xm</em>l doesn\'t have to have a root node.</p>\n'}, {'answer_id': 534077, 'author': 'mattwright', 'author_id': 33106, 'author_profile': 'https://Stackoverflow.com/users/33106', 'pm_score': 0, 'selected': False, 'text': '<p>Apache Xerces, for example, should support Xinclude, but you will need to enable it.</p>\n\n<p><a href="http://xerces.apache.org/xerces2-j/faq-xinclude.html" rel="nofollow noreferrer">http://xerces.apache.org/xerces2-j/faq-xinclude.html</a></p>\n\n<pre><code>import javax.xml.parsers.SAXParserFactory;\n\nSAXParserFactory spf = SAXParserFactory.newInstance();\nspf.setNamespaceAware(true);\nspf.setXIncludeAware(true);\n</code></pre>\n\n<p>Their documentation also says you can enable it as a <a href="http://xerces.apache.org/xerces2-j/features.html#xinclude" rel="nofollow noreferrer">feature</a></p>\n'}, {'answer_id': 1302238, 'author': 'denny', 'author_id': 159557, 'author_profile': 'https://Stackoverflow.com/users/159557', 'pm_score': 0, 'selected': False, 'text': '<p>This works now:</p>\n\n<pre><code>&lt;?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?&gt;\n&lt;installation version="1.0"&gt;\n&lt;packs&gt;      \n    &lt;pack name="Transaction Service" id="Transaction Service" required="no" &gt;\n        &lt;xi:include href="example/File2.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /&gt;\n    &lt;/pack&gt;\n&lt;/packs&gt;\n</code></pre>\n\n<p>example/File2.xml</p>\n\n<pre><code>&lt;?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?&gt;\n&lt;xfragment&gt;\n    &lt;file src="..." /&gt;\n&lt;/xfragment&gt;\n</code></pre>\n'}, {'answer_id': 27536996, 'author': 'matfud', 'author_id': 4372321, 'author_profile': 'https://Stackoverflow.com/users/4372321', 'pm_score': 0, 'selected': False, 'text': '<p>Just for anyone who wants to know. IzPack used nanoXML to parse all config files. It does not have namespaces. And does not handle xml includes.</p>\n\n<p>To resolve an issue I had I added the "xinclude" etc (fragment/fallback) element to the parser stuff so that it that mostly followed the standards for x:include (notice the name difference?) One is correct and has a namespace. The other is a nasty hack that pretends to follow the standard without using namespaces.</p>\n\n<p>Anyway this is long ago and now IzPack uses a sane XML parser and understands if you do it correctly xi:include or whatever prefix you wish to use there are no problems. It is standard in decent xml parsers.</p>\n'}]
['https://Stackoverflow.com/questions/72996', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']