Search in sources :

Example 21 with CDATASection

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

the class DocumentationEnricher method addDocumentation.

private void addDocumentation(Element item, String textContent) {
    Element annotation = document.createElement(Constants.XS_ANNOTATION_ELEMENT_NAME);
    Element documentation = document.createElement(Constants.XS_DOCUMENTATION_ELEMENT_NAME);
    documentation.setAttribute("xml:lang", "en");
    CDATASection cdataDocumentationText = document.createCDATASection(formatTextContent(item, textContent));
    documentation.appendChild(cdataDocumentationText);
    annotation.appendChild(documentation);
    if (item.getFirstChild() != null) {
        item.insertBefore(annotation, item.getFirstChild());
    } else {
        item.appendChild(annotation);
    }
}
Also used : CDATASection(org.w3c.dom.CDATASection) Element(org.w3c.dom.Element)

Example 22 with CDATASection

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

the class NormalizeTest method assertChildren.

private void assertChildren(Element element, String... texts) {
    List<String> actual = new ArrayList<String>();
    NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node.getNodeType() == Node.TEXT_NODE) {
            actual.add(((Text) node).getData());
        } else if (node.getNodeType() == Node.CDATA_SECTION_NODE) {
            actual.add("<![CDATA[" + ((CDATASection) node).getData() + "]]>");
        } else {
            actual.add("<" + node.getNodeName() + ">");
        }
    }
    assertEquals(Arrays.asList(texts), actual);
}
Also used : CDATASection(org.w3c.dom.CDATASection) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList)

Example 23 with CDATASection

use of org.w3c.dom.CDATASection in project intellij-community by JetBrains.

the class InspectionDump method main.

@Override
public void main(String[] args) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.newDocument();
        Element inspections = document.createElement("Inspections");
        document.appendChild(inspections);
        List<InspectionToolWrapper> tools = InspectionToolRegistrar.getInstance().createTools();
        for (InspectionToolWrapper tool : tools) {
            Element inspection = document.createElement("Inspection");
            inspection.setAttribute("groupPath", StringUtil.join(tool.getGroupPath(), ";"));
            inspection.setAttribute("group", tool.getGroupDisplayName());
            inspection.setAttribute("name", tool.getDisplayName());
            inspection.setAttribute("level", tool.getDefaultLevel().getName());
            if (tool.getLanguage() != null) {
                inspection.setAttribute("language", tool.getLanguage());
            }
            Element description = document.createElement("description");
            CDATASection descriptionSection = document.createCDATASection(escapeCDATA(tool.loadDescription()));
            description.appendChild(descriptionSection);
            inspection.appendChild(description);
            inspections.appendChild(inspection);
        }
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        DOMSource source = new DOMSource(document);
        final String path = args.length == 2 ? args[1] : PathManager.getHomePath() + File.separator + "AllInspections.xml";
        StreamResult console = new StreamResult(new File(path));
        transformer.transform(source, console);
        System.exit(0);
    } catch (ParserConfigurationException | TransformerException e) {
        // noinspection CallToPrintStackTrace
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) CDATASection(org.w3c.dom.CDATASection) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Example 24 with CDATASection

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

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 25 with CDATASection

use of org.w3c.dom.CDATASection in project webservices-axiom by apache.

the class TestCreateOMTextCDATASection method runTest.

@Override
protected void runTest() throws Throwable {
    OMText text = metaFactory.getOMFactory().createOMText("cdata section content", OMNode.CDATA_SECTION_NODE);
    assertTrue(text instanceof CDATASection);
}
Also used : CDATASection(org.w3c.dom.CDATASection) OMText(org.apache.axiom.om.OMText)

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