use of org.w3c.dom.CharacterData in project knime-core by knime.
the class XmlDomComparer method areNodesEqual.
private static Diff areNodesEqual(final Node node1, final Node node2, final XmlDomComparerCustomizer l) {
// Check for incompatible types
if (node1.getNodeType() != node2.getNodeType()) {
return new Diff(node1, node1.getNodeType(), node2.getNodeType(), Type.TYPE_MISSMATCH);
}
switch(node1.getNodeType()) {
case Node.TEXT_NODE:
case Node.CDATA_SECTION_NODE:
case Node.COMMENT_NODE:
String textNode1 = ((CharacterData) node1).getData();
String textNode2 = ((CharacterData) node2).getData();
if (!Objects.equals(textNode1, textNode2)) {
return new Diff(node1, textNode1, textNode2, Type.TEXT_MISSMATCH);
}
return null;
case Node.DOCUMENT_NODE:
return areNodesEqual(((Document) node1).getDocumentElement(), ((Document) node2).getDocumentElement(), l);
case Node.ELEMENT_NODE:
// Different names means different nodes
Element element1 = (Element) node1;
Element element2 = (Element) node2;
Diff namesComparison = checkNamesAndNS(element1, element2);
if (namesComparison != null) {
return namesComparison;
}
Diff attributeComparison = areAttributesEqual(node1, node2, l);
if (attributeComparison != null) {
return attributeComparison;
}
return areChildsEqual(node1, node2, l);
case Node.PROCESSING_INSTRUCTION_NODE:
String piNode1 = ((ProcessingInstruction) node1).getData();
String piNode2 = ((ProcessingInstruction) node2).getData();
if (!Objects.equals(piNode1, piNode2)) {
return new Diff(node1, piNode1, piNode2, Type.TEXT_MISSMATCH);
}
return null;
default:
throw new IllegalArgumentException("Nodes with type: " + node1.getNodeType() + " are not supported");
}
}
use of org.w3c.dom.CharacterData in project ma-core-public by infiniteautomation.
the class DomUtil method getText.
/**
* Extract the textual content from a Node.
* This is rather like the XPath value of a Node.
* @param node The node to extract the text from
* @return The textual value of the node
*/
public static String getText(Node node) {
StringBuffer reply = new StringBuffer();
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if ((child instanceof CharacterData && !(child instanceof Comment)) || child instanceof EntityReference) {
reply.append(child.getNodeValue());
} else if (child.getNodeType() == Node.ELEMENT_NODE) {
reply.append(getText(child));
}
}
return reply.toString();
}
use of org.w3c.dom.CharacterData in project spring-framework by spring-projects.
the class DomUtils method getTextValue.
/**
* Extracts the text value from the given DOM element, ignoring XML comments.
* <p>Appends all CharacterData nodes and EntityReference nodes into a single
* String value, excluding Comment nodes. Only exposes actual user-specified
* text, no default values of any kind.
* @see CharacterData
* @see EntityReference
* @see Comment
*/
public static String getTextValue(Element valueEle) {
Assert.notNull(valueEle, "Element must not be null");
StringBuilder sb = new StringBuilder();
NodeList nl = valueEle.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node item = nl.item(i);
if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
sb.append(item.getNodeValue());
}
}
return sb.toString();
}
use of org.w3c.dom.CharacterData in project aries by apache.
the class ExtNamespaceHandler method getTextValue.
private static String getTextValue(Element element) {
StringBuffer value = new StringBuffer();
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node item = nl.item(i);
if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
value.append(item.getNodeValue());
}
}
return value.toString();
}
use of org.w3c.dom.CharacterData in project aries by apache.
the class Parser method getTextValue.
private static String getTextValue(Element element) {
StringBuffer value = new StringBuffer();
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node item = nl.item(i);
if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
value.append(item.getNodeValue());
}
}
return value.toString();
}
Aggregations