当前位置: 首页>>代码示例>>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;未经允许,请勿转载。