use of org.w3c.dom.Comment in project robovm by robovm.
the class ImportNode method testImportNode4.
public void testImportNode4() throws Throwable {
Document doc;
Document aNewDoc;
DocumentFragment docFrag;
Comment comment;
Node aNode;
NodeList children;
Node child;
String childValue;
doc = (Document) load("staff", builder);
aNewDoc = (Document) load("staff", builder);
docFrag = aNewDoc.createDocumentFragment();
comment = aNewDoc.createComment("descendant1");
aNode = docFrag.appendChild(comment);
aNode = doc.importNode(docFrag, true);
children = aNode.getChildNodes();
assertEquals("throw_Size", 1, children.getLength());
child = aNode.getFirstChild();
childValue = child.getNodeValue();
assertEquals("descendant1", "descendant1", childValue);
}
use of org.w3c.dom.Comment in project robovm by robovm.
the class ImportNode method testImportNode3.
public void testImportNode3() throws Throwable {
Document doc;
Document aNewDoc;
Comment comment;
Node aNode;
Document ownerDocument;
DocumentType docType;
String system;
String value;
doc = (Document) load("staffNS", builder);
aNewDoc = (Document) load("staffNS", builder);
comment = aNewDoc.createComment("this is a comment");
aNode = doc.importNode(comment, false);
ownerDocument = aNode.getOwnerDocument();
assertNotNull("ownerDocumentNotNull", ownerDocument);
docType = ownerDocument.getDoctype();
system = docType.getSystemId();
assertURIEquals("systemId", null, null, null, "staffNS.dtd", null, null, null, null, system);
value = aNode.getNodeValue();
assertEquals("nodeValue", "this is a comment", value);
}
use of org.w3c.dom.Comment in project generator by mybatis.
the class XmlFileMergerJaxp method isGeneratedNode.
private static boolean isGeneratedNode(Node node) {
boolean rc = false;
if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
//$NON-NLS-1$
String id = element.getAttribute("id");
if (id != null) {
for (String prefix : MergeConstants.OLD_XML_ELEMENT_PREFIXES) {
if (id.startsWith(prefix)) {
rc = true;
break;
}
}
}
if (rc == false) {
// check for new node format - if the first non-whitespace node
// is an XML comment, and the comment includes
// one of the old element tags,
// then it is a generated node
NodeList children = node.getChildNodes();
int length = children.getLength();
for (int i = 0; i < length; i++) {
Node childNode = children.item(i);
if (isWhiteSpace(childNode)) {
continue;
} else if (childNode.getNodeType() == Node.COMMENT_NODE) {
Comment comment = (Comment) childNode;
String commentData = comment.getData();
for (String tag : MergeConstants.OLD_ELEMENT_TAGS) {
if (commentData.contains(tag)) {
rc = true;
break;
}
}
} else {
break;
}
}
}
}
return rc;
}
use of org.w3c.dom.Comment 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.Comment 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();
}
Aggregations