List of usage examples for org.w3c.dom Node CDATA_SECTION_NODE
short CDATA_SECTION_NODE
To view the source code for org.w3c.dom Node CDATA_SECTION_NODE.
Click Source Link
CDATASection
. From source file:org.kalypsodeegree.xml.XMLTools.java
/** * Appends a node and it's children to the given StringBuffer. Indentation is added on recursion. *//*ww w .j ava2s.c o m*/ public static void appendNode(final Node node, final String indent, final StringBuffer sb) { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: { sb.append("<?xml version=\"1.0\"?>\n"); final Document doc = (Document) node; appendNode(doc.getDocumentElement(), "", sb); break; } case Node.ELEMENT_NODE: { final String name = node.getNodeName(); sb.append(indent + "<" + name); final NamedNodeMap attributes = node.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { final Node current = attributes.item(i); sb.append(" " + current.getNodeName() + "=\"" + current.getNodeValue() + "\""); } sb.append(">"); // Kinder durchgehen final NodeList children = node.getChildNodes(); if (children != null) { for (int i = 0; i < children.getLength(); i++) { appendNode(children.item(i), indent, sb); } } sb.append(indent + "</" + name + ">"); break; } case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: { final String trimmed = node.getNodeValue().trim(); if (!trimmed.equals("")) { sb.append(indent + trimmed); } break; } case Node.PROCESSING_INSTRUCTION_NODE: break; case Node.ENTITY_REFERENCE_NODE: break; case Node.DOCUMENT_TYPE_NODE: break; } }
From source file:org.kmallan.azureus.rssfeed.Scheduler.java
private static String getText(Node node) { StringBuffer sb = new StringBuffer(); node.normalize();//from w w w.j a va 2 s. c o m NodeList children = node.getChildNodes(); int childrenLen = children.getLength(), type; for (int iLoop = 0; iLoop < childrenLen; iLoop++) { Node child = children.item(iLoop); type = child.getNodeType(); if (type == Node.TEXT_NODE || type == Node.CDATA_SECTION_NODE) { sb.append(child.getNodeValue()); sb.append(" "); } } return sb.toString().trim(); }
From source file:ORG.oclc.os.SRW.SRUServerTester.java
private String getNodeText(Node doc, String xPath) { Node node = doc;//from w w w .ja v a 2s .c o m if (xPath != null) try { node = XPathAPI.selectSingleNode(doc, xPath, ns); } catch (TransformerException e) { return null; } String strRet = ""; if (null != node) { if (node.getNodeType() == Node.ATTRIBUTE_NODE) return node.getNodeValue(); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node item = children.item(i); switch (item.getNodeType()) { case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: strRet += item.getNodeValue().trim(); } } } return strRet; }
From source file:org.openanzo.jdbc.opgen.RdbStatement.java
private static String getText(Node n) { NodeList nl = n.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n2 = nl.item(i);//from w w w.j a v a 2 s. c o m if (n2.getNodeType() == Node.TEXT_NODE) { String text = n2.getNodeValue(); if (text.trim().length() > 0) { return text; } } else if (n2.getNodeType() == Node.CDATA_SECTION_NODE) { return n2.getNodeValue(); } else { return getText(n); } } return null; }
From source file:org.osaf.cosmo.dav.acl.report.PrincipalPropertySearchReport.java
private boolean matchText(Element parent, String match) { NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) child; if (!matchText(e, match)) return false; } else if (child.getNodeType() == Node.TEXT_NODE || child.getNodeType() == Node.CDATA_SECTION_NODE) { String data = ((CharacterData) child).getData(); if (!matchText(data, match)) return false; } // else we skip the node }//w ww .java 2 s. c om return true; }
From source file:org.osaf.cosmo.xml.DomWriter.java
private static void writeNode(Node n, XMLStreamWriter writer) throws XMLStreamException { if (n.getNodeType() == Node.ELEMENT_NODE) writeElement((Element) n, writer); else if (n.getNodeType() == Node.CDATA_SECTION_NODE || n.getNodeType() == Node.TEXT_NODE) writeCharacters((CharacterData) n, writer); else/* ww w.j ava 2 s. co m*/ log.warn("Skipping element " + n.getNodeName()); }
From source file:org.pentaho.reporting.engine.classic.extensions.datasources.xpath.XPathTableModel.java
private boolean processNode(final Node node, final LinkedHashMap<String, String> results, final TypedTableModel typedTableModel) throws ReportDataFactoryException { final LinkedHashMap<String, String> innerResults = new LinkedHashMap<String, String>(results); boolean isLeaf = true; // System.out.println("<" + node.getQName() + ">"); final NodeList childList = node.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { final Node nodeIf = childList.item(i); final short type = nodeIf.getNodeType(); if (type == Node.COMMENT_NODE) { continue; }// w ww . j a va 2s .c o m if (type == Node.ELEMENT_NODE) { final NodeList anIf = nodeIf.getChildNodes(); final int size = anIf.getLength(); // check if either a empty node or a if (size == 0) { // a empty node ... innerResults.put(nodeIf.getNodeName(), null); } else if (size == 1) { final Node subNode = anIf.item(0); if (subNode.getNodeType() == Node.TEXT_NODE || subNode.getNodeType() == Node.CDATA_SECTION_NODE) { // a single text node .. innerResults.put(nodeIf.getNodeName(), nodeIf.getTextContent()); } else if (subNode.getNodeType() == Node.ELEMENT_NODE) { isLeaf = false; } else { innerResults.put(nodeIf.getNodeName(), nodeIf.getTextContent()); } } else { isLeaf = false; } } else { final String content = nodeIf.getTextContent(); if (StringUtils.isEmpty(content, true) == false) { innerResults.put(nodeIf.getNodeName(), content); } } } if (isLeaf == false) { for (int i = 0; i < childList.getLength(); i++) { final Node deepNode = childList.item(i); if (deepNode.getNodeType() == Node.ELEMENT_NODE) { final NodeList childNodes = deepNode.getChildNodes(); if (childNodes.getLength() > 1 || (childNodes.getLength() == 1 && childNodes.item(0).getNodeType() == Node.ELEMENT_NODE)) { if (processNode(deepNode, innerResults, typedTableModel) == false) { return false; } } } } return true; } else { return addRow(innerResults, typedTableModel); } }
From source file:org.qi4j.valueserialization.stax.StaxValueDeserializer.java
@Override protected Object asSimpleValue(Node inputNode) throws Exception { if (inputNode == null) { return null; }/*from www . j a v a 2 s .c o m*/ if (inputNode.getNodeType() == Node.ELEMENT_NODE && "null".equals(inputNode.getLocalName())) { return null; } if (inputNode.getNodeType() != Node.TEXT_NODE && inputNode.getNodeType() != Node.CDATA_SECTION_NODE) { throw new ValueSerializationException("Expected a TEXT or CDATA node but got " + inputNode); } String stringValue = inputNode.getNodeValue(); return detectAndConvertStringValue(stringValue); }
From source file:org.sakaiproject.bbb.impl.bbbapi.BaseBBBAPI.java
protected Map<String, Object> processNode(Node _node) { Map<String, Object> map = new HashMap<String, Object>(); NodeList responseNodes = _node.getChildNodes(); for (int i = 0; i < responseNodes.getLength(); i++) { Node node = responseNodes.item(i); String nodeName = node.getNodeName().trim(); if (node.getChildNodes().getLength() == 1 && (node.getChildNodes().item(0).getNodeType() == org.w3c.dom.Node.TEXT_NODE || node.getChildNodes().item(0).getNodeType() == org.w3c.dom.Node.CDATA_SECTION_NODE)) { String nodeValue = node.getTextContent(); map.put(nodeName, nodeValue != null ? nodeValue.trim() : null); } else if (node.getChildNodes().getLength() == 0 && node.getNodeType() != org.w3c.dom.Node.TEXT_NODE && node.getNodeType() != org.w3c.dom.Node.CDATA_SECTION_NODE) { map.put(nodeName, ""); } else if (node.getChildNodes().getLength() >= 1 && node.getChildNodes().item(0).getChildNodes().item(0) .getNodeType() != org.w3c.dom.Node.TEXT_NODE && node.getChildNodes().item(0).getChildNodes().item(0) .getNodeType() != org.w3c.dom.Node.CDATA_SECTION_NODE) { List<Object> list = new ArrayList<Object>(); for (int c = 0; c < node.getChildNodes().getLength(); c++) { Node n = node.getChildNodes().item(c); list.add(processNode(n)); }// w w w . j a va 2 s . co m map.put(nodeName, list); } else { map.put(nodeName, processNode(node)); } } return map; }
From source file:org.sakaiproject.tool.assessment.qti.util.XmlUtil.java
/** * Get a textual representation of a Node. * @param node The Node/*from w ww. j a v a2 s . co m*/ * @return the document in a text string */ public static String getDOMString(Node node) { //String domString = ""; StringBuilder domStringbuf = new StringBuilder(); int type = node.getNodeType(); switch (type) { // print the document element case Node.DOCUMENT_NODE: { domStringbuf.append("<?xml version=\"1.0\" ?>\n"); domStringbuf.append(getDOMString(((Document) node).getDocumentElement())); break; } // print element with attributes case Node.ELEMENT_NODE: { domStringbuf.append("<"); domStringbuf.append(node.getNodeName()); NamedNodeMap attrs = node.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); //domString += (" " + attr.getNodeName().trim() + // "=\"" + attr.getNodeValue().trim() + // "\""); domStringbuf.append((" " + attr.getNodeName().trim() + "=\"" + attr.getNodeValue().trim() + "\"")); } //domString = domStringbuf.toString(); domStringbuf.append(">"); NodeList children = node.getChildNodes(); if (children != null) { int len = children.getLength(); for (int i = 0; i < len; i++) domStringbuf.append(getDOMString(children.item(i))); } domStringbuf.append("</"); domStringbuf.append(node.getNodeName()); domStringbuf.append(">\n"); break; } // handle entity reference nodes case Node.ENTITY_REFERENCE_NODE: { domStringbuf.append("&"); domStringbuf.append(node.getNodeName().trim()); domStringbuf.append(";"); break; } // print cdata sections case Node.CDATA_SECTION_NODE: { domStringbuf.append(""); break; } // print text case Node.TEXT_NODE: { String val = node.getNodeValue(); if (val == null) val = ""; domStringbuf.append(val);//rshastri .trim() removed SAK-1671 break; } // print processing instruction case Node.PROCESSING_INSTRUCTION_NODE: { domStringbuf.append(""); break; } } if (type == Node.ELEMENT_NODE) { domStringbuf.append("\n"); } String domString = domStringbuf.toString(); return domString; }