protected Document documentRoot() throws Exception { CruiseConfig cruiseConfig = goConfigDao.loadForEditing(); ByteArrayOutputStream out = new ByteArrayOutputStream(); new MagicalGoConfigXmlWriter(configCache, registry).write(cruiseConfig, out, true); Document document = reader.read(new StringReader(out.toString())); Map<String, String> map = new HashMap<>(); map.put("go", MagicalGoConfigXmlWriter.XML_NS); //TODO: verify this doesn't cache the factory DocumentFactory factory = DocumentFactory.getInstance(); factory.setXPathNamespaceURIs(map); return document; }
private SAXReader createXmlReader() { DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs( Collections.singletonMap("m", "http://maven.apache.org/POM/4.0.0")); return new SAXReader(factory); }
/** * <p>Simple init for the SAX Reader.</p> * */ private void saxInit() { namespaces = new HashMap<String, String>(); DocumentFactory docFactory = new DocumentFactory(); docFactory.setXPathNamespaceURIs(namespaces); saxReader = new SAXReader(docFactory); }
/** * @param inputStream */ @Override public void parse(InputStream inputStream) { failedTests = new ArrayList<>(); inconclusiveTests = new ArrayList<>(); passedTests = new ArrayList<>(); try { final Map<String, String> uris = Collections.singletonMap("g", "http://www.gallio.org/"); final DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(uris); // parse or create a document final SAXReader reader = new SAXReader(SecureXmlParserFactory.newXmlReader()); reader.setDocumentFactory(factory); final Document document = reader.read(inputStream); parse(document); } catch (Exception e) { log.error("Failed to parse xml test results.", e); } }
private Document readSpringConfiguration() { final File springFile = getSpringFile(); InputStream is = null; if (springFile !=null && springFile.exists() && springFile.isFile()) { try { is = new FileInputStream(springFile); } catch (FileNotFoundException ex) { log.error("Problem reading Spring configuration file.", ex); } } else { // no Spring configuration present yet, use template. final String path = "/xml/valuelistmanager.xml"; is = getClass().getResourceAsStream(path); } if (is != null) { try { Map<String, String> namespaceUris = new HashMap<>(); namespaceUris.put("beans", "http://www.springframework.org/schema/beans"); DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(namespaceUris); SAXReader reader = new SAXReader(); reader.setDocumentFactory(factory); return reader.read(is); } catch (DocumentException ex) { log.error("Problem parsing Spring configuration file.", ex); } } return null; }
/** * @param inputStream */ @Override public void parse(InputStream inputStream) { log.info("Beginning parse of MSTest results file"); failedTests = new ArrayList<>(); passedTests = new ArrayList<>(); inconclusiveTests = new ArrayList<>(); try { Map<String, String> uris = ImmutableMap.of( VS_2006_PREFIX, "http://microsoft.com/schemas/VisualStudio/TeamTest/2006", VS_2010_PREFIX, "http://microsoft.com/schemas/VisualStudio/TeamTest/2010"); DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(uris); // parse or create a document final SAXReader reader = new SAXReader(SecureXmlParserFactory.newXmlReader()); reader.setDocumentFactory(factory); Document document = reader.read(inputStream); parse(document); log.info("Finished parse of MSTest results file"); } catch (Exception e) { log.error("Failed to parse xml test results.", e); } }
docFactory.setXPathNamespaceURIs(namespaces); saxReader = new SAXReader(docFactory);
f.setXPathNamespaceURIs(NAMESPACE_MAP); Document jelly = new SAXReader(f).read(tagFile); Element doc = (Element) jelly.selectSingleNode(".//s:documentation");
factory.setXPathNamespaceURIs(uris);
/** * Tests the use of namespace URI Mapping associated with a DocumentFactory * * @throws Exception * DOCUMENT ME! */ public void testNamespaceUriMap() throws Exception { // register namespace prefix->uri mappings with factory Map<String, String> uris = new HashMap<String, String>(); uris.put("x", "fooNamespace"); uris.put("y", "barNamespace"); DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(uris); // parse or create a document SAXReader reader = new SAXReader(); reader.setDocumentFactory(factory); Document doc = getDocument("/xml/test/nestedNamespaces.xml", reader); // evaluate XPath using registered namespace prefixes // which do not appear in the document (though the URIs do!) String value = doc.valueOf("/x:pizza/y:cheese/x:pepper"); log("Found value: " + value); assertEquals("XPath used default namesapce URIS", "works", value); }