NodeList nodelist = node.getChildNodes(); for (int i = 0; i < nodelist.getLength(); i++) subString += "<![CDATA[" + ((CDATASection) child).getData() + "]]>"; String cdata = ((Text) child).getData(); if (cdata!=null) NamedNodeMap attributes = node.getAttributes(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < attributes.getLength(); i++) String attributeNodeValue = attribute.getNodeValue(); if (attributeNodeValue!=null)
String nodeValue = node.getNodeValue(); int endIndex = nodeValue.indexOf("]]>"); if ((fFeatures & SPLITCDATA) != 0) {
CDATASection section =(CDATASection) m_currentNode.getLastChild(); section.appendData(s);
private static void writeNode(Node node, XmlOutput out) { final NodeList childNodes; switch (node.getNodeType()) { case Node.DOCUMENT_NODE: out.print("<?xml version=\"1.0\" ?>\n"); childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); final Node att = attributeMap.item(i); out.attribute( att.getNodeName(), att.getNodeValue()); CDATASection cdata = (CDATASection) node; out.cdata( cdata.getNodeValue(), true); break; final String wholeText = text.getNodeValue(); if (!isWhitespace(wholeText)) { out.cdata(wholeText, false);
public static String toDebugString(Node node) { short type = node.getNodeType(); switch (type) { case Node.ATTRIBUTE_NODE: { return "cdata[" + cdataSection.getData() + "]"; return "text[" + text.getData() + "]"; return node.getNodeName();
if(nextChild.getNodeType() == Node.TEXT_NODE) { char[] value = ((Text)nextChild).getNodeValue().toCharArray(); getContentHandler().characters(value, 0, value.length); } else if(nextChild.getNodeType() == Node.COMMENT_NODE) { char[] value = ((Comment)nextChild).getNodeValue().toCharArray(); if (lexicalHandler != null) { lexicalHandler.comment(value, 0, value.length); } else if(nextChild.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element)nextChild; reportElementEvents(childElement); lexicalHandler.startCDATA(); char[] value = ((CDATASection)nextChild).getData().toCharArray(); getContentHandler().characters(value, 0, value.length); if(lexicalHandler != null) {
private String getCDataOrText(Element element) { StringBuilder content = new StringBuilder(); NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); short nodeType = child.getNodeType(); if (nodeType == Node.TEXT_NODE) { content.append(child.getTextContent()); } else if (nodeType == Node.CDATA_SECTION_NODE) { return ((CDATASection) child).getData(); } else { throw new EntityBuilderException("Unexpected set variable assertion expression node type: " + child.getNodeName()); } } return content.toString(); }
/** Characters. */ @Override public void characters(XMLString text, Augmentations augs) throws XNIException { if (fInCDATASection) { final Node node = fCurrentNode.getLastChild(); if (node != null && node.getNodeType() == Node.CDATA_SECTION_NODE) { final CDATASection cdata = (CDATASection)node; cdata.appendData(text.toString()); } else { final CDATASection cdata = fDocument.createCDATASection(text.toString()); fCurrentNode.appendChild(cdata); } } else { final Node node = fCurrentNode.getLastChild(); if (node != null && node.getNodeType() == Node.TEXT_NODE) { final Text textNode = (Text)node; textNode.appendData(text.toString()); } else { final Text textNode = fDocument.createTextNode(text.toString()); fCurrentNode.appendChild(textNode); } } }
/** * Return the text content of an Element, or null if no such text content exists */ public static String getElementText(Element e) { if (e != null) { Node node = e.getFirstChild(); StringBuilder builder = new StringBuilder(); boolean found = false; while (node != null) { if (Node.TEXT_NODE == node.getNodeType()) { found = true; builder.append(((Text)node).getData()); } else if (Node.CDATA_SECTION_NODE == node.getNodeType()) { found = true; builder.append(((CDATASection)node).getData()); } node = node.getNextSibling(); } if (!found) { return null; } return builder.toString(); } return null; }
public final String getElementValue2( Node elem ) { Node child; if( elem != null){ if (elem.hasChildNodes()){ for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){ if(child.getNodeType() == Node.CDATA_SECTION_NODE){ CDATASection cdata = (CDATASection)child; cdata =cdata.getData().toString(); } } } }
/** * Returns the child text from a DOM node. * @param node the node to parse * @return the node text, or <tt>null</tt> if the node did not contain any text */ public static String getText(Node node) { StringBuilder s = null; Node child = node.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.TEXT_NODE) { if (s == null) { s = new StringBuilder(); } s.append(((Text)child).getTextContent()); } else if (child.getNodeType() == Node.CDATA_SECTION_NODE) { if (s == null) { s = new StringBuilder(); } s.append(((CDATASection)child).getData()); } child = child.getNextSibling(); } return s == null ? null : s.toString(); }
/** * @param xmlNode XML node * @param xmlStreamWriter XML stream writer * @throws XMLStreamException the XML stream exception */ public static void writeNode(Node xmlNode, XMLStreamWriter xmlStreamWriter) throws XMLStreamException { if (xmlNode instanceof Element) { addElement((Element) xmlNode, xmlStreamWriter); } else if (xmlNode instanceof Text) { xmlStreamWriter.writeCharacters(xmlNode.getNodeValue()); } else if (xmlNode instanceof CDATASection) { xmlStreamWriter.writeCData(((CDATASection) xmlNode).getData()); } else if (xmlNode instanceof Comment) { xmlStreamWriter.writeComment(((Comment) xmlNode).getData()); } else if (xmlNode instanceof EntityReference) { xmlStreamWriter.writeEntityRef(xmlNode.getNodeValue()); } else if (xmlNode instanceof ProcessingInstruction) { ProcessingInstruction procInst = (ProcessingInstruction) xmlNode; xmlStreamWriter.writeProcessingInstruction(procInst.getTarget(), procInst.getData()); } else if (xmlNode instanceof Document) { writeToDocument((Document) xmlNode, xmlStreamWriter); } }
IterableNodeList childNodes = new IterableNodeList(subtreeRoot.getChildNodes()); for (Node node : childNodes) { switch (node.getNodeType()) { case ELEMENT_NODE: traceSubTree((Element) node); case TEXT_NODE: Text text = (Text) node; contentBuffer.append(text.getData()); break; case CDATA_SECTION_NODE: CDATASection cdata = (CDATASection) node; contentBuffer.append(cdata.getData()); break;
public String getCDATA() { StringBuilder sb = new StringBuilder(); List<Node> nodes = getChildNodes(Document.CDATA_SECTION_NODE); for (Node node : nodes) { if (node.getNodeType() == Document.CDATA_SECTION_NODE) { String val = ((CDATASection) node).getData(); if (val != null) { sb.append(val); } } } return sb.toString(); }
private Node appendToCursor(String data) { if (cursor == null) { Element doc = document.getDocumentElement(); if( doc != null ){ cursor = doc; } else { cursor = document; } } if (cursor.getNodeType() == Node.CDATA_SECTION_NODE) { CDATASection section = (CDATASection) cursor; section.appendData(data); return section; } else { return appendToCursor(document.createTextNode(data)); } }
@Override public void endCDATA() throws SAXException { CDATASection cdata = (CDATASection)nodes.get(nodes.size()-1).getFirstChild(); if (stringBuffer.length() > 0) { cdata.setData(stringBuffer.toString()); stringBuffer.reset(); } }
/** * INTERNAL: */ public void characters(String value) { if (value.length() > 0) { if (node instanceof CDATASection) { ((CDATASection) node).setData(value); } else { node.appendChild(document.createTextNode(value)); } } }
/** * Receive notification of character data. * * @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. */ @Override public void characters(char[] ch, int start, int length) throws SAXException { if (getState() == State.DOCUMENTATION) { if (getMixedContentState() == MixedContentState.CDATA) { this.currentMixedContentCDataSection.appendData(new String( ch, start, length)); } else if (getMixedContentState() != MixedContentState.ENTITY) { this.currentMixedContentNode .appendChild(this.mixedContentDocument .createTextNode(new String(ch, start, length))); } } }
/** * Checks if an CDATASection node is well-formed, by checking it's data * for well-formedness. Note that the presence of a CDATA termination mark * in the contents of a CDATASection is handled by the parameter * spli-cdata-sections * * @param data The contents of the comment node */ protected void isCDATASectionWellFormed(CDATASection node) { // Does the data valid XML character data Character invalidChar = isWFXMLChar(node.getData()); //if (!isWFXMLChar(node.getData(), invalidChar)) { if (invalidChar != null) { String msg = Utils.messages.createMessage( MsgKey.ER_WF_INVALID_CHARACTER_IN_CDATA, new Object[] { Integer.toHexString(Character.getNumericValue(invalidChar.charValue())) }); if (fErrorHandler != null) { fErrorHandler.handleError( new DOMErrorImpl( DOMError.SEVERITY_FATAL_ERROR, msg, MsgKey.ER_WF_INVALID_CHARACTER, null, null, null)); } } }