本文整理匯總了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");
}