The list of methods to do XML CData are organized into topic(s).
String
getCharacterData(Element el) Gets the character data corresponding to the given DOM element.
Text text = getChildTextNode(el);
return text == null ? null : text.getData();
String
getCharacterDataFromElement(Element e) get Character Data From Element
org.w3c.dom.Node child = e.getFirstChild();
if (child instanceof CharacterData) {
CharacterData cd = (CharacterData) child;
return cd.getData();
return "?";
String
getCharacterDataFromElement(Element e) get Character Data From Element
if (e != null) {
Node child = e.getFirstChild();
if (child instanceof CharacterData) {
CharacterData cd = (CharacterData) child;
return cd.getData();
return "?";
...
String
getCharacterDataFromElement(Element e) get Character Data From Element
Node child = e.getFirstChild();
if (child instanceof CharacterData) {
CharacterData cd = (CharacterData) child;
return cd.getData();
} else {
return "?";
String
getCharacterDataFromElementWithKey(final Element element, final String key) get Character Data From Element With Key
String result = null;
if (element != null) {
final NodeList jobNodeList = element.getElementsByTagName(key);
final Node node = jobNodeList.item(0);
if (node != null) {
final CharacterData characterData = (CharacterData) jobNodeList.item(0).getChildNodes().item(0);
if (characterData != null) {
result = characterData.getNodeValue();
...
String
parseCdataSection(Node cdataParentNode) parse Cdata Section
if (cdataParentNode == null)
return "";
StringBuilder sb = new StringBuilder();
NodeList cdataParentNodeChildren = cdataParentNode.getChildNodes();
if (cdataParentNodeChildren != null && cdataParentNodeChildren.getLength() > 0) {
for (int i = 0; i < cdataParentNodeChildren.getLength(); i++) {
Node cdataNode = cdataParentNodeChildren.item(i);
if (CDATA_SECTION.equalsIgnoreCase(cdataNode.getNodeName()))
...
void
removeEmptyCDATASections(Node node) Remove empty CDATA sections from the given node and all of its descendants.
Node child = node.getFirstChild();
while (child != null) {
Node next = child.getNextSibling();
switch (child.getNodeType()) {
case Node.CDATA_SECTION_NODE:
if (child.getNodeValue().length() == 0) {
child.getParentNode().removeChild(child);
break;
case Node.ELEMENT_NODE:
removeEmptyCDATASections(child);
child = next;
void
setTextValue(Node node, String value, boolean cdata) set Text Value
if (node != null) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.TEXT_NODE && !cdata) {
((Text) child).setNodeValue(value);
return;
if (child.getNodeType() == Node.CDATA_SECTION_NODE && cdata) {
...