views:

1231

answers:

4

I am creating an installer in IzPack. It is quite large, and I have broken up my XML files appropriately using <xinclude> and <xfragment> 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.

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.

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

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

Format of XML for example purposes: File1.xml

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

File2.xml

<xfragment>
    <file src="..." />
</xfragment>

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.)

What I am looking to have produced:

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

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

Tim Reynolds

A: 

I'm not sure if java supports automatic xinclude. But you will have to use namespaces to make it work. So don't use <xinclude ....>, but use:

<xi:xinclude xmlns:xi="http://www.w3.org/2001/XInclude" href="example/File2.xml" />

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.

Paul de Vrieze
Unfortunately, IzPack does not support namespaces.http://izpack.org/documentation/installation-files.html#xinclude-style-constructsBut, knowing that I can't expect it to be handled automatically with Java is good to know. I am going through the IzPack source right now. They use NanoXML...
+1  A: 

If you can't get xinclude to work and you're using Ant, I'd recommend XMLTask, 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.

e.g.

<xmltask source="templatefile.xml" dest="finalfile.xml">
  <insert path="/packs/pack[1]" position="under" file="pack1.xml"/>
</xmltask>

(warning- the above is done from memory so please consult the documentation!).

Note that in the above, the file pack1.xml doesn't have to have a root node.

Brian Agnew
A: 

Apache Xerces, for example, should support Xinclude, but you will need to enable it.

http://xerces.apache.org/xerces2-j/faq-xinclude.html

import javax.xml.parsers.SAXParserFactory;

SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setXIncludeAware(true);

Their documentation also says you can enable it as a feature

mattwright
A: 

This works now:

<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
<installation version="1.0">
<packs>      
    <pack name="Transaction Service" id="Transaction Service" required="no" >
        <xi:include href="example/File2.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
    </pack>
</packs>

example/File2.xml

<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
<xfragment>
    <file src="..." />
</xfragment>
denny