當前位置: 首頁>>代碼示例>>Java>>正文


Java Document.removeChild方法代碼示例

本文整理匯總了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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:JavaProjectNatureTest.java

示例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");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:JavaActionsTest.java


注:本文中的org.w3c.dom.Document.removeChild方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。