class Poco::XML::CDATASection

Overview

CDATA sections are used to escape blocks of text containing characters that would otherwise be regarded as markup. More…

#include <CDATASection.h>

class CDATASection: public Poco::XML::Text
{
public:
    // methods

    Text*
    splitText(unsigned long offset);

    virtual
    const XMLString&
    nodeName() const;

    virtual
    unsigned short
    nodeType() const;

protected:
    // construction

    CDATASection(
        Document* pOwnerDocument,
        const XMLString& data
        );

    CDATASection(
        Document* pOwnerDocument,
        const CDATASection& sec
        );

    // methods

    virtual
    Node*
    copyNode(
        bool deep,
        Document* pOwnerDocument
        ) const;
};

Inherited Members

public:
    // typedefs

    typedef Poco::XML::NamespaceSupport NSMap;

    // enums

    enum
    {
        ELEMENT_NODE                = 1,
        ATTRIBUTE_NODE,
        TEXT_NODE,
        CDATA_SECTION_NODE,
        ENTITY_REFERENCE_NODE,
        ENTITY_NODE,
        PROCESSING_INSTRUCTION_NODE,
        COMMENT_NODE,
        DOCUMENT_NODE,
        DOCUMENT_TYPE_NODE,
        DOCUMENT_FRAGMENT_NODE,
        NOTATION_NODE,
    };

    // methods

    void
    duplicate() const;

    void
    release() const;

    virtual
    void
    autoRelease() = 0;

    virtual
    void
    addEventListener(
        const XMLString& type,
        EventListener* listener,
        bool useCapture
        ) = 0;

    virtual
    void
    removeEventListener(
        const XMLString& type,
        EventListener* listener,
        bool useCapture
        ) = 0;

    virtual
    bool
    dispatchEvent(Event* evt) = 0;

    virtual
    const XMLString&
    nodeName() const = 0;

    const XMLString&
    nodeValue() const;

    virtual
    const XMLString&
    getNodeValue() const = 0;

    virtual
    void
    setNodeValue(const XMLString& value) = 0;

    virtual
    unsigned short
    nodeType() const = 0;

    virtual
    Node*
    parentNode() const = 0;

    virtual
    NodeList*
    childNodes() const = 0;

    virtual
    Node*
    firstChild() const = 0;

    virtual
    Node*
    lastChild() const = 0;

    virtual
    Node*
    previousSibling() const = 0;

    virtual
    Node*
    nextSibling() const = 0;

    virtual
    NamedNodeMap*
    attributes() const = 0;

    virtual
    Document*
    ownerDocument() const = 0;

    virtual
    Node*
    insertBefore(
        Node* newChild,
        Node* refChild
        ) = 0;

    virtual
    Node*
    replaceChild(
        Node* newChild,
        Node* oldChild
        ) = 0;

    virtual
    Node*
    removeChild(Node* oldChild) = 0;

    virtual
    Node*
    appendChild(Node* newChild) = 0;

    virtual
    bool
    hasChildNodes() const = 0;

    virtual
    Node*
    cloneNode(bool deep) const = 0;

    virtual
    void
    normalize() = 0;

    virtual
    bool
    isSupported(
        const XMLString& feature,
        const XMLString& version
        ) const = 0;

    virtual
    const XMLString&
    namespaceURI() const = 0;

    virtual
    XMLString
    prefix() const = 0;

    virtual
    const XMLString&
    localName() const = 0;

    virtual
    bool
    hasAttributes() const = 0;

    virtual
    XMLString
    innerText() const = 0;

    virtual
    Node*
    getNodeByPath(const XMLString& path) const = 0;

    virtual
    Node*
    getNodeByPathNS(
        const XMLString& path,
        const NSMap& nsMap
        ) const = 0;

    virtual
    const XMLString&
    nodeName() const;

    virtual
    const XMLString&
    getNodeValue() const;

    virtual
    void
    setNodeValue(const XMLString& value);

    virtual
    Node*
    parentNode() const;

    virtual
    NodeList*
    childNodes() const;

    virtual
    Node*
    firstChild() const;

    virtual
    Node*
    lastChild() const;

    virtual
    Node*
    previousSibling() const;

    virtual
    Node*
    nextSibling() const;

    virtual
    NamedNodeMap*
    attributes() const;

    virtual
    Document*
    ownerDocument() const;

    virtual
    Node*
    insertBefore(
        Node* newChild,
        Node* refChild
        );

    virtual
    Node*
    replaceChild(
        Node* newChild,
        Node* oldChild
        );

    virtual
    Node*
    removeChild(Node* oldChild);

    virtual
    Node*
    appendChild(Node* newChild);

    virtual
    bool
    hasChildNodes() const;

    virtual
    Node*
    cloneNode(bool deep) const;

    virtual
    void
    normalize();

    virtual
    bool
    isSupported(
        const XMLString& feature,
        const XMLString& version
        ) const;

    virtual
    const XMLString&
    namespaceURI() const;

    virtual
    XMLString
    prefix() const;

    virtual
    const XMLString&
    localName() const;

    virtual
    bool
    hasAttributes() const;

    virtual
    void
    addEventListener(
        const XMLString& type,
        EventListener* listener,
        bool useCapture
        );

    virtual
    void
    removeEventListener(
        const XMLString& type,
        EventListener* listener,
        bool useCapture
        );

    virtual
    bool
    dispatchEvent(Event* evt);

    virtual
    XMLString
    innerText() const;

    virtual
    Node*
    getNodeByPath(const XMLString& path) const;

    virtual
    Node*
    getNodeByPathNS(
        const XMLString& path,
        const NSMap& nsMap
        ) const;

    virtual
    void
    autoRelease();

    const XMLString&
    data() const;

    const XMLString&
    getData() const;

    void
    setData(const XMLString& data);

    unsigned long
    length() const;

    XMLString
    substringData(
        unsigned long offset,
        unsigned long count
        ) const;

    void
    appendData(const XMLString& arg);

    void
    insertData(
        unsigned long offset,
        const XMLString& arg
        );

    void
    deleteData(
        unsigned long offset,
        unsigned long count
        );

    void
    replaceData(
        unsigned long offset,
        unsigned long count,
        const XMLString& arg
        );

    XMLString
    trimmedData() const;

    virtual
    const XMLString&
    getNodeValue() const;

    virtual
    void
    setNodeValue(const XMLString& value);

    Text*
    splitText(unsigned long offset);

    virtual
    const XMLString&
    nodeName() const;

    virtual
    unsigned short
    nodeType() const;

    virtual
    XMLString
    innerText() const;

protected:
    // fields

    static const XMLString EMPTY_STRING;

    // methods

    virtual
    Node*
    copyNode(
        bool deep,
        Document* pOwnerDocument
        ) const = 0;

    virtual
    bool
    events() const;

    virtual
    bool
    eventsSuspended() const;

    void
    captureEvent(Event* evt);

    void
    bubbleEvent(Event* evt);

    void
    dispatchSubtreeModified();

    void
    dispatchNodeInserted();

    void
    dispatchNodeRemoved();

    virtual
    void
    dispatchNodeRemovedFromDocument();

    virtual
    void
    dispatchNodeInsertedIntoDocument();

    void
    dispatchAttrModified(
        Attr* pAttr,
        MutationEvent::AttrChangeType changeType,
        const XMLString& prevValue,
        const XMLString& newValue
        );

    void
    dispatchCharacterDataModified(
        const XMLString& prevValue,
        const XMLString& newValue
        );

    void
    setOwnerDocument(Document* pOwnerDocument);

    virtual
    Node*
    copyNode(
        bool deep,
        Document* pOwnerDocument
        ) const;

Detailed Documentation

CDATA sections are used to escape blocks of text containing characters that would otherwise be regarded as markup.

The only delimiter that is recognized in a CDATA section is the “]]>” string that ends the CDATA section. CDATA sections cannot be nested. Their primary purpose is for including material such as XML fragments, without needing to escape all the delimiters.

The DOMString attribute of the Text node holds the text that is contained by the CDATA section. Note that this may contain characters that need to be escaped outside of CDATA sections and that, depending on the character encoding (“charset”) chosen for serialization, it may be impossible to write out some characters as part of a CDATA section.

The CDATASection interface inherits from the CharacterData interface through the Text interface. Adjacent CDATASection nodes are not merged by use of the normalize method on the Element interface.

Note: Because no markup is recognized within a CDATASection, character numeric references cannot be used as an escape mechanism when serializing. Therefore, action needs to be taken when serializing a CDATASection with a character encoding where some of the contained characters cannot be represented. Failure to do so would not produce well-formed XML. One potential solution in the serialization process is to end the CDATA section before the character, output the character using a character reference or entity reference, and open a new CDATA section for any further characters in the text node. Note, however, that some code conversion libraries at the time of writing do not return an error or exception when a character is missing from the encoding, making the task of ensuring that data is not corrupted on serialization more difficult.

Methods

virtual
const XMLString&
nodeName() const

Returns the name of this node, depending on its type.

virtual
unsigned short
nodeType() const

Returns a code representing the type of the underlying object.