XML technologies / XML / XML in a Nutshell / DOM reference / Object reference / CDATASection

(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)

The interface CDATASection contains the raw data, untouched by the parser, of a CDATA block in the XML document. Although this interface is derived from the Text interface, multiple consecutive CDATASection nodes are not merged into a single node when the normalize( ) method of the Element interface is called.

Java example

// Öffne eine XML-Datei
try {
    FileInputStream fis = new FileInputStream("phone_list.xml");
    StringBuffer sb = new StringBuffer(  );
    // Lies die XML-Datei in den Speicher
    int ch;
    while ((ch = fis.read(  )) != −1) {
        sb.append((char)ch);
    }

    // Nun erzeugen wir ein Objekt vom Typ CDATASection, das genau die gerade
    // gelesenen Daten als CDATA-Abschnitt enthält
    CDATASection ndCDATA = doc.createCDATASection(sb.toString(  ));
} catch (IOException e) {
    ...

CDATASection is simply a subclass of the Text interface and defines no attributes or methods of its own. For details of methods for accessing the text data, see the page on the Text interface.

  

 

 

 

back to top