List of usage examples for javax.xml.parsers DocumentBuilder isXIncludeAware
public boolean isXIncludeAware()
Get the XInclude processing mode for this parser.
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);//from w ww .j av a2 s .c o m factory.setXIncludeAware(true); DocumentBuilder parser = factory.newDocumentBuilder(); System.out.println("aware: " + parser.isXIncludeAware()); Document document = parser.parse(args[0]); Transformer transformer = TransformerFactory.newInstance().newTransformer(); Source source = new DOMSource(document); Result output = new StreamResult(System.out); transformer.transform(source, output); }
From source file:com.pieframework.model.repository.ModelStore.java
/** * @param xmlFile//from www. j av a 2 s .c om * @param writer * @throws ParserConfigurationException * @throws SAXException * @throws IOException * @throws TransformerException */ protected static void processXIncludes(File xmlFile, Writer writer) throws ParserConfigurationException, SAXException, IOException, TransformerException { final InputStream xml = new FileInputStream(xmlFile); // This sets the base where XIncludes are resolved InputSource i = new InputSource(xml); i.setSystemId(xmlFile.toURI().toString()); // Configure Document Builder DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setXIncludeAware(true); factory.setNamespaceAware(true); factory.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", false); DocumentBuilder docBuilder = factory.newDocumentBuilder(); if (!docBuilder.isXIncludeAware()) { throw new IllegalStateException(); } // Parse the InputSource Document doc = docBuilder.parse(i); // output Source source = new DOMSource(doc); Result result = new StreamResult(writer); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(source, result); }