Search in sources :

Example 16 with Comment

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);
}
Also used : Comment(org.w3c.dom.Comment) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 17 with Comment

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);
}
Also used : Comment(org.w3c.dom.Comment) Node(org.w3c.dom.Node) DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document)

Example 18 with Comment

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;
}
Also used : Comment(org.w3c.dom.Comment) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString)

Example 19 with Comment

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();
}
Also used : Comment(org.w3c.dom.Comment) CharacterData(org.w3c.dom.CharacterData) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) EntityReference(org.w3c.dom.EntityReference)

Example 20 with Comment

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();
}
Also used : Comment(org.w3c.dom.Comment) CharacterData(org.w3c.dom.CharacterData) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) EntityReference(org.w3c.dom.EntityReference)

Aggregations

Comment (org.w3c.dom.Comment)22 Node (org.w3c.dom.Node)14 NodeList (org.w3c.dom.NodeList)13 Element (org.w3c.dom.Element)9 EntityReference (org.w3c.dom.EntityReference)8 CharacterData (org.w3c.dom.CharacterData)7 Document (org.w3c.dom.Document)7 DocumentType (org.w3c.dom.DocumentType)2 ProcessingInstruction (org.w3c.dom.ProcessingInstruction)2 Text (org.w3c.dom.Text)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 Enumeration (java.util.Enumeration)1 InvalidPropertiesFormatException (java.util.InvalidPropertiesFormatException)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1