⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e540. adding a cdata section to a dom document.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
If `]]>' appears in the CDATA section's text, the default XML writers in J2SE 1.4 automatically break the CDATA section into two CDATA sections; `]]' will appear at the end of the first section while `>' will appear at the beginning of the second section. 
    // Obtain an XML document; this method is implemented in
    // e510 The Quintessential Program to Create a DOM Document from an XML File
    Document doc = parseXmlFile("infilename.xml", false);
    
    // Add a CDATA section to the root element
    Element element = doc.getDocumentElement();
    CDATASection cdata = doc.createCDATASection("data");
    element.appendChild(cdata);
    
    // If "]]>" appears in the text, two CDATA sections will be written out
    cdata = doc.createCDATASection("more]]>data");
    element.appendChild(cdata);

This is the sample input for the example: 
    <?xml version="1.0" encoding="UTF-8"?>
    <map>
        <entry key="key1" value="value1" />
        <entry key="key2" />
    </map>

The resulting XML from running the example is: 
    <?xml version="1.0" encoding="UTF-8"?>
    <map>
        <entry key="key1" value="value1"/>
        <entry key="key2"/>
    <![CDATA[data]]><![CDATA[more]]]]><![CDATA[>data]]></map>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -