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);
}
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations