List of usage examples for org.dom4j DocumentFactory setXPathNamespaceURIs
public void setXPathNamespaceURIs(Map<String, String> namespaceURIs)
From source file:org.pentaho.aggdes.model.ssas.ConversionUtil.java
License:Open Source License
public static Document parseAssl(final InputStream input) throws DocumentException, IOException { Map<String, String> uris = new HashMap<String, String>(); uris.put("assl", "http://schemas.microsoft.com/analysisservices/2003/engine"); uris.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); uris.put("xs", "http://www.w3.org/2001/XMLSchema"); uris.put("msprop", "urn:schemas-microsoft-com:xml-msprop"); uris.put("msdata", "urn:schemas-microsoft-com:xml-msdata"); DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(uris); SAXReader reader = new SAXReader(); reader.setDocumentFactory(factory);// w w w. j a va 2 s . c o m // get bytes from InputStream and cache them so they can be read multiple times byte[] bytes = IOUtils.toByteArray(input); ByteArrayInputStream byteInput = new ByteArrayInputStream(bytes); // try default encoding first, then fall back on iso-8859-1 Document document = null; try { logger.debug("attempting to parse assuming utf-8 encoding"); document = reader.read(byteInput); } catch (DocumentException e) { // retry reader.setEncoding("iso-8859-1"); // exception will propagate if it fails to read with iso-8859-1 logger.debug("parse failed; attempting to parse assuming iso=8859-1 encoding"); // start over from the first byte by creating a new stream byteInput = new ByteArrayInputStream(bytes); document = reader.read(byteInput); } return document; }