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