Skip to main content

XInclude and JAXB

Posted by kohsuke on January 13, 2006 at 1:49 PM PST

XInclude is really just a very simple filtering. So all you need is a bit of SAX programming to put together pieces in the right order. The idea is that you parse XML, run it through XInclude filter (that expands inclusion), then feed it to JAXB unmarshaller. By using xincluder, it would be:

<br />import com.elharo.xml.xinclude.XIncludeFilter;<br />import javax.xml.bind.*;<br /><br />JAXBContext context = ...;<br />uh = context.createUnmarshaller().getUnmarshallerHandler();<br /><br />// create a parser<br />spf = SAXParserFactory.newInstance();<br />spf.setNamespaceAware(true);<br />xr = spf.newSAXParser().getXMLReader();<br /><br />// hook things up<br />XIncludeFilter includer = new XIncludeFilter();<br />includer.setParent(xr);<br />includer.setContentHandler(uh);<br /><br />// and run!<br />includer.parse(xmlToParse);<br />
Related Topics >>