private Document extractDocument(final InputSource inputSource) throws SAXException { try { DocumentBuilder builder = documentBuilder(); Document document = builder.parse(inputSource); document.normalizeDocument(); trimNode(document); return document; } catch (IOException e) { throw new MocoException(e); } } }
public XmlAopConfigration(String... fileNames) throws ParserConfigurationException, SAXException, IOException { DocumentBuilder builder = Lang.xmls(); Document document; List<AopConfigrationItem> aopList = new ArrayList<AopConfigrationItem>(); List<NutResource> list = Scans.me().loadResource(null, fileNames); for (NutResource nutResource : list) { document = builder.parse(nutResource.getInputStream()); document.normalizeDocument(); NodeList nodeListZ = ((Element) document.getDocumentElement()).getElementsByTagName("class"); for (int i = 0; i < nodeListZ.getLength(); i++) aopList.add(parse((Element) nodeListZ.item(i))); } setAopItemList(aopList); }
public XmlIocLoader(String... fileNames) { try { DocumentBuilder builder = Lang.xmls(); Document document; List<NutResource> list = Scans.me().loadResource(getScanPatten(), fileNames); for (NutResource nr : list) { InputStream ins = nr.getInputStream(); document = builder.parse(ins); document.normalizeDocument(); NodeList nodeListZ = ((Element) document.getDocumentElement()).getChildNodes(); for (int i = 0; i < nodeListZ.getLength(); i++) { if (nodeListZ.item(i) instanceof Element) paserBean((Element) nodeListZ.item(i), false); } Streams.safeClose(ins); } handleParent(); if (LOG.isDebugEnabled()) LOG.debugf("Load complete :\n%s", Json.toJson(iocMap)); } catch (Throwable e) { throw Lang.wrapThrow(e); } }
/** * Compares two DOM {@link Node nodes} by comparing the representations of * the nodes as XML strings * * @param node1 the first node * @param node2 the second node * @return true if the XML representation node1 is the same as the XML * representation of node2, otherwise false */ public static boolean compareNodes(Node node1, Node node2) { Validate.notNull(node1, "First node required"); Validate.notNull(node2, "Second node required"); // The documents need to be cloned as normalization has side-effects node1 = node1.cloneNode(true); node2 = node2.cloneNode(true); // The documents need to be normalized before comparison takes place to // remove any formatting that interfere with comparison if (node1 instanceof Document && node2 instanceof Document) { ((Document) node1).normalizeDocument(); ((Document) node2).normalizeDocument(); } else { node1.normalize(); node2.normalize(); } return nodeToString(node1).equals(nodeToString(node2)); }
public static void validate(Document d, String schema, DOMErrorHandler handler) { DOMConfiguration config = d.getDomConfig(); config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema"); config.setParameter("validate", true); config.setParameter("schema-location", schema); config.setParameter("resource-resolver", new ClasspathResourceResolver()); config.setParameter("error-handler", handler); d.normalizeDocument(); }
/** * @inheritDoc */ public void normalizeDocument() { dom.normalizeDocument(); }
@Override public void normalizeDocument() { original_.normalizeDocument(); }
public static DOMSource toDOMSource(final Document document) { // normalize the document to assure the resolution of each node namespace document.normalizeDocument(); return new DOMSource(document); }
/** * Create a Source from a DOM document. * * @param document * A DOM document * @return the Source built from the DOM document */ public static DOMSource createSource(final Document document) { // normalize the document to assure the resolution of each node // namespace document.normalizeDocument(); return new DOMSource(document); }
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setCoalescing(true); dbf.setIgnoringElementContentWhitespace(true); dbf.setIgnoringComments(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc1 = db.parse(new File("file1.xml")); doc1.normalizeDocument(); Document doc2 = db.parse(new File("file2.xml")); doc2.normalizeDocument(); Assert.assertTrue(doc1.isEqualNode(doc2));
/** * Pulls the root element of a DOM document. * @param document the document * @param normalize whether or not to normalize the document * @return the element */ public Element pull(Document document, boolean normalize) { if (normalize) { document.normalizeDocument(); } return pull(document.getDocumentElement(), normalize); }
/** * * @see org.w3c.dom.Document#normalizeDocument() */ public void normalizeDocument() { getParent().normalizeDocument(); }
/** * Pulls the root element of a DOM document. * @param document the document * @param normalize whether or not to normalize the document * @return the element */ public Element pull(Document document, boolean normalize) { if (normalize) { document.normalizeDocument(); } return pull(document.getDocumentElement(), normalize); }
protected Document queryOutHints2XmlDom(List<QueryDocument.StoredFieldMetadata> outFieldsHints, Fields aHintedFields) throws Exception { Document queryDom = documentBuilder.newDocument(); queryDom.setXmlStandalone(true); Node outputFieldsNode = queryDom.createElement(QueryDocument.OUTPUT_FIELDS_TAG_NAME); saveOutputFields(outFieldsHints, aHintedFields, queryDom, outputFieldsNode); queryDom.appendChild(outputFieldsNode); queryDom.normalizeDocument(); return queryDom; }
public D parse(InputSource source, boolean validate) throws ParserException { try { DocumentBuilder parser = createFactory(validate).newDocumentBuilder(); parser.setEntityResolver(this); parser.setErrorHandler(this); Document dom = parser.parse(source); dom.normalizeDocument(); return createDOM(dom); } catch (Exception ex) { throw unwrapException(ex); } }
/** * DOM3 method: Normalize the document with namespaces * @param doc * @return */ public static Document normalizeNamespaces(Document doc) { DOMConfiguration docConfig = doc.getDomConfig(); docConfig.setParameter("namespaces", Boolean.TRUE); doc.normalizeDocument(); return doc; }
/** * DOM3 method: Normalize the document with namespaces * * @param doc * @return */ public static Document normalizeNamespaces(Document doc) { DOMConfiguration docConfig = doc.getDomConfig(); docConfig.setParameter("namespaces", Boolean.TRUE); doc.normalizeDocument(); return doc; }
/** * DOM3 method: Normalize the document with namespaces * @param doc * @return */ public static Document normalizeNamespaces(Document doc) { DOMConfiguration docConfig = doc.getDomConfig(); docConfig.setParameter("namespaces", Boolean.TRUE); doc.normalizeDocument(); return doc; }
/** Invoke code that may trigger leak */ public static void triggerLeak() throws ParserConfigurationException { // Alternative 1 DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument().normalizeDocument(); // Alternative 2 Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); DOMImplementationLS implementation = (DOMImplementationLS)document.getImplementation(); implementation.createLSSerializer().writeToString(document); } }
public static void validate(Document d, String schema, DOMErrorHandler handler) { DOMConfiguration config = d.getDomConfig(); config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema"); config.setParameter("validate", true); config.setParameter("schema-location", schema); config.setParameter("resource-resolver", new ClasspathResourceResolver()); config.setParameter("error-handler", handler); d.normalizeDocument(); }