newTimemlNode.appendChild(annotatedDoc.importNode(extraInfoNode, true)); newTimemlNode.appendChild(annotatedDoc.adoptNode(annotatedTextElem)); annotatedDoc.appendChild(newTimemlNode);
} else { Node compDesc = oneXML.getDocumentElement().getElementsByTagName(cd.getComponentTypeString()).item(0); allXML.getDocumentElement().appendChild(allXML.adoptNode(compDesc));
} else { Node compDesc = oneXML.getDocumentElement().getElementsByTagName(cd.getComponentTypeString()).item(0); allXML.getDocumentElement().appendChild(allXML.adoptNode(compDesc));
String xml = "<hello><world /></hello>"; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document0 = db.parse(new InputSource(new StringReader(xml))); Document document1 = db.newDocument(); NodeList nodeList = document0.getDocumentElement().getChildNodes(); document1.appendChild(document1.adoptNode(nodeList.item(0).cloneNode(true))); // Serialize the two documents to check that the copy was correct. ByteArrayOutputStream output = new ByteArrayOutputStream(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(new DOMSource(document0), new StreamResult(output)); System.out.println(output.toString("UTF-8")); output.reset(); transformer.transform(new DOMSource(document1), new StreamResult(output)); System.out.println(output.toString("UTF-8")); } catch (TransformerException e) { } catch (IOException e) { } catch (SAXException e) { } catch (ParserConfigurationException e) { }
/** * @inheritDoc */ public Node adoptNode(Node source) throws DOMException { return dom.adoptNode(source); }
protected void appendFragment ( final Element parent, final URL url ) throws Exception { final DocumentBuilder db = this.dbf.newDocumentBuilder (); final InputSource is = new InputSource ( url.openStream () ); final Document doc = db.parse ( is ); Element ele = doc.getDocumentElement (); ele = (Element)parent.getOwnerDocument ().adoptNode ( ele ); parent.appendChild ( ele ); }
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); Document tournament = builder.parse(new File("b.xml")); Document tournaments = builder.parse(new File("a.xml")); Node tournamentElement = tournament.getFirstChild(); Node ndetournament = tournaments.getDocumentElement(); Node firstDocImportedNode = tournaments.adoptNode(tournamentElement); ndetournament.appendChild(firstDocImportedNode); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(tournaments), new StreamResult(System.out));
public static Document createDocument(Element element, String docElementName) throws Exception { DocumentBuilder builder = DocumentBuilderFactory.newInstance() .newDocumentBuilder(); Document doc = builder.newDocument(); Element root = doc.createElement(docElementName); doc.appendChild(root); root.appendChild(doc.adoptNode(element.cloneNode(true))); return doc; }
protected void appendFragment ( final Element parent, final String fragment ) throws Exception { Element ele = parseFragment ( fragment ); ele = (Element)parent.getOwnerDocument ().adoptNode ( ele ); parent.appendChild ( ele ); }
public static Element replaceChild(Element parentNode, Element newNode, Element oldNode) { // Si el elemento a agregar no pertenece al documento a agregar if (newNode.getOwnerDocument() != oldNode.getOwnerDocument()) { newNode = (Element) oldNode.getOwnerDocument().adoptNode(newNode); } parentNode.replaceChild(newNode, oldNode); return newNode; } }
protected void appendFragment ( final Element parent, final String fragment ) throws Exception { Element ele = parseFragment ( fragment ); ele = (Element)parent.getOwnerDocument ().adoptNode ( ele ); parent.appendChild ( ele ); }
private static Document isolateDescendant(final Element mathElement, final Element descendant) { Document result = XMLUtilities.createNSAwareDocumentBuilder().newDocument(); Element resultMathElement = (Element) mathElement.cloneNode(false); result.adoptNode(resultMathElement); result.appendChild(resultMathElement); Element firstSemanticElementCopy = (Element) descendant.cloneNode(true); result.adoptNode(firstSemanticElementCopy); resultMathElement.appendChild(firstSemanticElementCopy); return result; } }
private void doSubstituteVariableValue(final Element miElement, final MathsContentOutputValueWrapper value) { final Node parentNode = miElement.getParentNode(); /* Need to adopt a clone of the (single) child of the enclosing <math> element in the isolated PMathML Element */ final Node pmathContent = value.getPMathMLElement().getChildNodes().item(0); final Node pmathContentCloned = pmathContent.cloneNode(true); final Node importedNode = parentNode.getOwnerDocument().adoptNode(pmathContentCloned); /* Replace <mi/> element with this value */ parentNode.replaceChild(importedNode, miElement); } }
protected void runTest() throws Throwable { DocumentBuilder builder = dbf.newDocumentBuilder(); Document document = builder.newDocument(); Element parent = document.createElementNS(null, "test"); Text node = document.createTextNode("test"); parent.appendChild(node); assertSame(node, document.adoptNode(node)); assertSame(document, node.getOwnerDocument()); assertNull(node.getParentNode()); assertNull(parent.getFirstChild()); } }
private Document toDocument(final DocumentFragment fragment) { try { final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); doc.appendChild(doc.adoptNode(fragment)); return doc; } catch (ParserConfigurationException e) { throw new RuntimeException(e); } }
public void processChildNodes(Node result, Node source) { NodeList childNodes = source.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(0).cloneNode(true); result.getOwnerDocument().adoptNode(child); result.appendChild(child); } } }
public void processChildNodes(Node result, Node source) { NodeList childNodes = source.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(0).cloneNode(true); result.getOwnerDocument().adoptNode(child); result.appendChild(child); } } }
private void runTest(String tagName, String tagMarkup, String templateMarkup, String expectedResult) throws GadgetException, IOException { Element templateDef = parseTemplate(templateMarkup); Element tagInstance = parseTemplate(tagMarkup); templateDef.getOwnerDocument().adoptNode(tagInstance); TagHandler tagHandler = new TemplateBasedTagHandler(tagInstance, TEST_NS, tagName); TagRegistry reg = new DefaultTagRegistry( ImmutableSet.of(tagHandler, new RepeatTagHandler())); DocumentFragment result = processor.processTemplate(templateDef, context, resolver, reg); String output = serialize(result); assertEquals(expectedResult, output); }
private void runTest(String tagName, String tagMarkup, String templateMarkup, String expectedResult) throws GadgetException, IOException { Element templateDef = parseTemplate(templateMarkup); Element tagInstance = parseTemplate(tagMarkup); templateDef.getOwnerDocument().adoptNode(tagInstance); TagHandler tagHandler = new TemplateBasedTagHandler(tagInstance, TEST_NS, tagName); TagRegistry reg = new DefaultTagRegistry( ImmutableSet.of(tagHandler, new RepeatTagHandler())); DocumentFragment result = processor.processTemplate(templateDef, context, resolver, reg); String output = serialize(result); assertEquals(expectedResult, output); }
private void runTest(String tagName, String tagMarkup, String templateMarkup, String expectedResult) throws GadgetException, IOException { Element templateDef = parseTemplate(templateMarkup); Element tagInstance = parseTemplate(tagMarkup); templateDef.getOwnerDocument().adoptNode(tagInstance); TagHandler tagHandler = new TemplateBasedTagHandler(tagInstance, TEST_NS, tagName); TagRegistry reg = new DefaultTagRegistry( ImmutableSet.of(tagHandler, new RepeatTagHandler())); DocumentFragment result = processor.processTemplate(templateDef, context, resolver, reg); String output = serialize(result); assertEquals(expectedResult, output); }