本文整理汇总了Java中org.w3c.dom.Document.removeChild方法的典型用法代码示例。如果您正苦于以下问题:Java Document.removeChild方法的具体用法?Java Document.removeChild怎么用?Java Document.removeChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Document
的用法示例。
在下文中一共展示了Document.removeChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: upgradeSchemaTestImpl
import org.w3c.dom.Document; //导入方法依赖的package包/类
private void upgradeSchemaTestImpl(String from, String to) throws Exception {
// Formatting has to be the same as Xerces' formatter produces for this test to pass:
String xml1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<java-data xmlns=\""+from+"\">\n" +
" <!-- Hello there. -->\n" +
" <foo bar=\"baz\" quux=\"whatever\">hello</foo>\n" +
" <x>OK</x>\n" +
"</java-data>\n";
String xml2expected = xml1.replaceAll(from, to);
Document doc1 = XMLUtil.parse(new InputSource(new StringReader(xml1)), false, true, null, null);
Element el1 = doc1.getDocumentElement();
Element el2 = LookupProviderImpl.upgradeSchema(el1,to);
Document doc2 = XMLUtil.createDocument(JavaProjectNature.EL_JAVA, to, null, null);
doc2.removeChild(doc2.getDocumentElement());
doc2.appendChild(doc2.importNode(el2, true));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLUtil.write(doc2, baos, "UTF-8");
String xml2actual = baos.toString("UTF-8").replaceAll(System.getProperty("line.separator"), "\n");
assertEquals("Correct upgrade result", xml2expected, xml2actual);
}
示例2: xmlToString
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Format XML as a string. Assumes Xerces serializer in current impl.
* Collapse all comments to no body.
*/
private static String xmlToString(Element el) throws Exception {
Document doc = XMLUtil.createDocument("fake", null, null, null);
doc.removeChild(doc.getDocumentElement());
doc.appendChild(doc.importNode(el, true));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLUtil.write(doc, baos, "UTF-8");
return baos.toString("UTF-8").replaceAll("<!--([^-]|-[^-])*-->", "<!---->").replaceAll(System.getProperty("line.separator"), "\n");
}