Search in sources :

Example 31 with CDATASection

use of org.w3c.dom.CDATASection in project j2objc by google.

the class DOMBuilder method cdata.

/**
 * Receive notification of cdata.
 *
 * <p>The Parser will call this method to report each chunk of
 * character data.  SAX parsers may return all contiguous character
 * data in a single chunk, or they may split it into several
 * chunks; however, all of the characters in any single event
 * must come from the same external entity, so that the Locator
 * provides useful information.</p>
 *
 * <p>The application must not attempt to read from the array
 * outside of the specified range.</p>
 *
 * <p>Note that some parsers will report whitespace using the
 * ignorableWhitespace() method rather than this one (validating
 * parsers must do so).</p>
 *
 * @param ch The characters from the XML document.
 * @param start The start position in the array.
 * @param length The number of characters to read from the array.
 * @see #ignorableWhitespace
 * @see org.xml.sax.Locator
 */
public void cdata(char[] ch, int start, int length) throws org.xml.sax.SAXException {
    if (isOutsideDocElem() && org.apache.xml.utils.XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
        // avoid DOM006 Hierarchy request error
        return;
    String s = new String(ch, start, length);
    CDATASection section = (CDATASection) m_currentNode.getLastChild();
    section.appendData(s);
}
Also used : CDATASection(org.w3c.dom.CDATASection)

Example 32 with CDATASection

use of org.w3c.dom.CDATASection in project nutch by apache.

the class DOMBuilder method cdata.

/**
 * Receive notification of cdata.
 *
 * <p>
 * The Parser will call this method to report each chunk of character data.
 * SAX parsers may return all contiguous character data in a single chunk, or
 * they may split it into several chunks; however, all of the characters in
 * any single event must come from the same external entity, so that the
 * Locator provides useful information.
 * </p>
 *
 * <p>
 * The application must not attempt to read from the array outside of the
 * specified range.
 * </p>
 *
 * <p>
 * Note that some parsers will report whitespace using the
 * ignorableWhitespace() method rather than this one (validating parsers must
 * do so).
 * </p>
 *
 * @param ch
 *          The characters from the XML document.
 * @param start
 *          The start position in the array.
 * @param length
 *          The number of characters to read from the array.
 * @see #ignorableWhitespace
 * @see org.xml.sax.Locator
 */
public void cdata(char[] ch, int start, int length) throws org.xml.sax.SAXException {
    if (isOutsideDocElem() && XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
        // avoid DOM006 Hierarchy request error
        return;
    String s = new String(ch, start, length);
    // XXX ab@apache.org: modified from the original, to accomodate TagSoup.
    Node n = m_currentNode.getLastChild();
    if (n instanceof CDATASection)
        ((CDATASection) n).appendData(s);
    else if (n instanceof Comment)
        ((Comment) n).appendData(s);
}
Also used : Comment(org.w3c.dom.Comment) CDATASection(org.w3c.dom.CDATASection) Node(org.w3c.dom.Node)

Example 33 with CDATASection

use of org.w3c.dom.CDATASection in project nutch by apache.

the class DOMBuilder method cdata.

/**
 * Receive notification of cdata.
 *
 * <p>
 * The Parser will call this method to report each chunk of character data.
 * SAX parsers may return all contiguous character data in a single chunk, or
 * they may split it into several chunks; however, all of the characters in
 * any single event must come from the same external entity, so that the
 * Locator provides useful information.
 * </p>
 *
 * <p>
 * The application must not attempt to read from the array outside of the
 * specified range.
 * </p>
 *
 * <p>
 * Note that some parsers will report whitespace using the
 * ignorableWhitespace() method rather than this one (validating parsers must
 * do so).
 * </p>
 *
 * @param ch
 *          The characters from the XML document.
 * @param start
 *          The start position in the array.
 * @param length
 *          The number of characters to read from the array.
 * @see #ignorableWhitespace
 * @see org.xml.sax.Locator
 * @throws org.xml.sax.SAXException if text is found before
 * the document element
 */
public void cdata(char[] ch, int start, int length) throws org.xml.sax.SAXException {
    if (isOutsideDocElem() && XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
        // avoid DOM006 Hierarchy request error
        return;
    String s = new String(ch, start, length);
    // XXX ab@apache.org: modified from the original, to accomodate TagSoup.
    Node n = m_currentNode.getLastChild();
    if (n instanceof CDATASection)
        ((CDATASection) n).appendData(s);
    else if (n instanceof Comment)
        ((Comment) n).appendData(s);
}
Also used : Comment(org.w3c.dom.Comment) CDATASection(org.w3c.dom.CDATASection) Node(org.w3c.dom.Node)

Example 34 with CDATASection

use of org.w3c.dom.CDATASection in project zm-mailbox by Zimbra.

the class W3cDomUtil method toFlattened.

private static Element toFlattened(Node node, ElementFactory factory) {
    Element elt = factory.createElement(dom4jQNameForNode(node));
    makeAttributes(elt, node);
    StringBuilder content = new StringBuilder();
    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        switch(child.getNodeType()) {
            case Node.ELEMENT_NODE:
                // i.e. add textual representation of the XML
                content.append(W3cDomUtil.asXML(child, false));
                break;
            case Node.TEXT_NODE:
                content.append(child.getNodeValue());
                break;
            case Node.CDATA_SECTION_NODE:
                CDATASection cdata = (CDATASection) child;
                content.append(cdata.getData());
                break;
        }
    }
    return elt.setText(content.toString());
}
Also used : CDATASection(org.w3c.dom.CDATASection) Node(org.w3c.dom.Node)

Example 35 with CDATASection

use of org.w3c.dom.CDATASection in project pmd by pmd.

the class RuleSetWriter method createCDATASectionElement.

private Element createCDATASectionElement(String name, String value) {
    Element element = document.createElementNS(RULESET_2_0_0_NS_URI, name);
    CDATASection cdataSection = document.createCDATASection(value);
    element.appendChild(cdataSection);
    return element;
}
Also used : CDATASection(org.w3c.dom.CDATASection) Element(org.w3c.dom.Element)

Aggregations

CDATASection (org.w3c.dom.CDATASection)38 Element (org.w3c.dom.Element)19 Node (org.w3c.dom.Node)15 Document (org.w3c.dom.Document)14 NodeList (org.w3c.dom.NodeList)9 Text (org.w3c.dom.Text)9 Comment (org.w3c.dom.Comment)6 File (java.io.File)4 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 Transformer (javax.xml.transform.Transformer)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 DOMSource (javax.xml.transform.dom.DOMSource)2 StreamResult (javax.xml.transform.stream.StreamResult)2