Example usage for org.w3c.dom Node DOCUMENT_FRAGMENT_NODE

List of usage examples for org.w3c.dom Node DOCUMENT_FRAGMENT_NODE

Introduction

In this page you can find the example usage for org.w3c.dom Node DOCUMENT_FRAGMENT_NODE.

Prototype

short DOCUMENT_FRAGMENT_NODE

To view the source code for org.w3c.dom Node DOCUMENT_FRAGMENT_NODE.

Click Source Link

Document

The node is a DocumentFragment.

Usage

From source file:Main.java

/**
 * Convert a node type to a string. For debug purpose only.
 * //from   www.  jav  a2  s .com
 * @param nodeType
 *            the node type
 * @return the string
 * @throws Exception
 *             the exception
 */
public static String nodeTypeToString(short nodeType) throws Exception {
    if (nodeType == Node.ELEMENT_NODE)
        return "ELEMENT_NODE";
    if (nodeType == Node.ATTRIBUTE_NODE)
        return "ATTRIBUTE_NODE";
    if (nodeType == Node.TEXT_NODE)
        return "TEXT_NODE";
    if (nodeType == Node.CDATA_SECTION_NODE)
        return "CDATA_SECTION_NODE";
    if (nodeType == Node.ENTITY_REFERENCE_NODE)
        return "ENTITY_REFERENCE_NODE";
    if (nodeType == Node.ENTITY_NODE)
        return "ENTITY_NODE";
    if (nodeType == Node.PROCESSING_INSTRUCTION_NODE)
        return "PROCESSING_INSTRUCTION_NODE";
    if (nodeType == Node.COMMENT_NODE)
        return "COMMENT_NODE";
    if (nodeType == Node.DOCUMENT_NODE)
        return "DOCUMENT_NODE";
    if (nodeType == Node.DOCUMENT_TYPE_NODE)
        return "DOCUMENT_TYPE_NODE";
    if (nodeType == Node.DOCUMENT_FRAGMENT_NODE)
        return "DOCUMENT_FRAGMENT_NODE";
    if (nodeType == Node.NOTATION_NODE)
        return "NOTATION_NODE";
    if (nodeType == Node.DOCUMENT_POSITION_DISCONNECTED)
        return "DOCUMENT_POSITION_DISCONNECTED";
    if (nodeType == Node.DOCUMENT_POSITION_PRECEDING)
        return "DOCUMENT_POSITION_PRECEDING";
    if (nodeType == Node.DOCUMENT_POSITION_FOLLOWING)
        return "DOCUMENT_POSITION_FOLLOWING";
    if (nodeType == Node.DOCUMENT_POSITION_CONTAINS)
        return "DOCUMENT_POSITION_CONTAINS";
    if (nodeType == Node.DOCUMENT_POSITION_CONTAINED_BY)
        return "DOCUMENT_POSITION_CONTAINED_BY";
    if (nodeType == Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC)
        return "DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC";

    throw new Exception("Unknown value : " + nodeType);
}

From source file:Main.java

public String getNodeType(Node node) {
    String type;/*from w ww  . j  ava 2 s .co m*/

    switch (node.getNodeType()) {
    case Node.ELEMENT_NODE: {
        type = "Element";
        break;
    }
    case Node.ATTRIBUTE_NODE: {
        type = "Attribute";
        break;
    }
    case Node.TEXT_NODE: {
        type = "Text";
        break;
    }
    case Node.CDATA_SECTION_NODE: {
        type = "CData section";
        break;
    }
    case Node.ENTITY_REFERENCE_NODE: {
        type = "Entity reference";
        break;
    }
    case Node.ENTITY_NODE: {
        type = "Entity";
        break;
    }
    case Node.PROCESSING_INSTRUCTION_NODE: {
        type = "Processing instruction";
        break;
    }
    case Node.COMMENT_NODE: {
        type = "Comment";
        break;
    }
    case Node.DOCUMENT_NODE: {
        type = "Document";
        break;
    }
    case Node.DOCUMENT_TYPE_NODE: {
        type = "Document type";
        break;
    }
    case Node.DOCUMENT_FRAGMENT_NODE: {
        type = "Document fragment";
        break;
    }
    case Node.NOTATION_NODE: {
        type = "Notation";
        break;
    }
    default: {
        type = "???";
        break;
    }
    }
    return type;
}

From source file:Main.java

/**
 * Returns String representation of specified xml node.
 *
 * @param node   the specified xml node/*ww w  .ja v a2  s .c  o m*/
 * @return string representation of the node
 */
public static String getNodeData(Node node) {
    switch (node.getNodeType()) {
    case Node.DOCUMENT_FRAGMENT_NODE:
    case Node.DOCUMENT_NODE:
    case Node.ELEMENT_NODE: {
        /*for (Node child = node.getFirstChild(); null != child;
          child = child.getNextSibling())*/
        Node child = node.getFirstChild();
        if (child != null)
            return getNodeData(child);
    }
        break;
    case Node.TEXT_NODE:
    case Node.CDATA_SECTION_NODE:
        return node.getNodeValue();
    case Node.ATTRIBUTE_NODE:
        return node.getNodeValue();
    case Node.PROCESSING_INSTRUCTION_NODE:
        break;
    default:
        break;
    }
    return "";
}

From source file:TreeDumper2.java

private void dumpLoop(Node node, String indent) {
    switch (node.getNodeType()) {
    case Node.ATTRIBUTE_NODE:
        dumpAttributeNode((Attr) node, indent);
        break;// ww w. j  a  v a 2 s. c  o m
    case Node.CDATA_SECTION_NODE:
        dumpCDATASectionNode((CDATASection) node, indent);
        break;
    case Node.COMMENT_NODE:
        dumpCommentNode((Comment) node, indent);
        break;
    case Node.DOCUMENT_NODE:
        dumpDocument((Document) node, indent);
        break;
    case Node.DOCUMENT_FRAGMENT_NODE:
        dumpDocumentFragment((DocumentFragment) node, indent);
        break;
    case Node.DOCUMENT_TYPE_NODE:
        dumpDocumentType((DocumentType) node, indent);
        break;
    case Node.ELEMENT_NODE:
        dumpElement((Element) node, indent);
        break;
    case Node.ENTITY_NODE:
        dumpEntityNode((Entity) node, indent);
        break;
    case Node.ENTITY_REFERENCE_NODE:
        dumpEntityReferenceNode((EntityReference) node, indent);
        break;
    case Node.NOTATION_NODE:
        dumpNotationNode((Notation) node, indent);
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        dumpProcessingInstructionNode((ProcessingInstruction) node, indent);
        break;
    case Node.TEXT_NODE:
        dumpTextNode((Text) node, indent);
        break;
    default:
        System.out.println(indent + "Unknown node");
        break;
    }

    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++)
        dumpLoop(list.item(i), indent + "   ");
}

From source file:MainClass.java

private void dumpLoop(Node node, String indent) {
    switch (node.getNodeType()) {
    case Node.CDATA_SECTION_NODE:
        System.out.println(indent + "CDATA_SECTION_NODE");
        break;/*  w w  w .ja  va2  s. com*/
    case Node.COMMENT_NODE:
        System.out.println(indent + "COMMENT_NODE");
        break;
    case Node.DOCUMENT_FRAGMENT_NODE:
        System.out.println(indent + "DOCUMENT_FRAGMENT_NODE");
        break;
    case Node.DOCUMENT_NODE:
        System.out.println(indent + "DOCUMENT_NODE");
        break;
    case Node.DOCUMENT_TYPE_NODE:
        System.out.println(indent + "DOCUMENT_TYPE_NODE");
        break;
    case Node.ELEMENT_NODE:
        System.out.println(indent + "ELEMENT_NODE");
        break;
    case Node.ENTITY_NODE:
        System.out.println(indent + "ENTITY_NODE");
        break;
    case Node.ENTITY_REFERENCE_NODE:
        System.out.println(indent + "ENTITY_REFERENCE_NODE");
        break;
    case Node.NOTATION_NODE:
        System.out.println(indent + "NOTATION_NODE");
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        System.out.println(indent + "PROCESSING_INSTRUCTION_NODE");
        break;
    case Node.TEXT_NODE:
        System.out.println(indent + "TEXT_NODE");
        break;
    default:
        System.out.println(indent + "Unknown node");
        break;
    }
    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++)
        dumpLoop(list.item(i), indent + "   ");
}

From source file:Main.java

public static void getNodeData(Node node, StringBuffer buf) {
    switch (node.getNodeType()) {
    case Node.DOCUMENT_FRAGMENT_NODE:
    case Node.DOCUMENT_NODE:
    case Node.ELEMENT_NODE: {
        for (Node child = node.getFirstChild(); null != child; child = child.getNextSibling()) {
            buf.append('<');
            buf.append(node.getNodeName());
            buf.append('>');
            getNodeData(child, buf);/*from w w  w.j  a va 2s . co m*/
            buf.append("</");
            buf.append(node.getNodeName());
            buf.append('>');
        }
    }
        break;
    case Node.TEXT_NODE:
    case Node.CDATA_SECTION_NODE:
        buf.append(node.getNodeValue());
        break;
    case Node.ATTRIBUTE_NODE:
        buf.append(node.getNodeValue());
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
        break;
    default:
        // ignore
        break;
    }
}

From source file:DOMDump.java

private void dumpLoop(Node node, String indent) {
    switch (node.getNodeType()) {
    case Node.CDATA_SECTION_NODE:
        System.out.println(indent + "CDATA_SECTION_NODE");
        break;//w  w  w  .  java  2  s  .c  o  m
    case Node.COMMENT_NODE:
        System.out.println(indent + "COMMENT_NODE");
        break;
    case Node.DOCUMENT_FRAGMENT_NODE:
        System.out.println(indent + "DOCUMENT_FRAGMENT_NODE");
        break;
    case Node.DOCUMENT_NODE:
        System.out.println(indent + "DOCUMENT_NODE");
        break;
    case Node.DOCUMENT_TYPE_NODE:
        System.out.println(indent + "DOCUMENT_TYPE_NODE");
        break;
    case Node.ELEMENT_NODE:
        System.out.println(indent + "ELEMENT_NODE");
        break;
    case Node.ENTITY_NODE:
        System.out.println(indent + "ENTITY_NODE");
        break;
    case Node.ENTITY_REFERENCE_NODE:
        System.out.println(indent + "ENTITY_REFERENCE_NODE");
        break;
    case Node.NOTATION_NODE:
        System.out.println(indent + "NOTATION_NODE");
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        System.out.println(indent + "PROCESSING_INSTRUCTION_NODE");
        break;
    case Node.TEXT_NODE:
        System.out.println(indent + "TEXT_NODE");
        break;
    default:
        System.out.println(indent + "Unknown node");
        break;
    }

    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++)
        dumpLoop(list.item(i), indent + "   ");

}

From source file:com.sun.faces.config.rules.DescriptionTextRule.java

/**
 * <p>Construct a variant of <code>NodeCreateRule</code> that will
 * create a <code>DocumentFragment</code> object.
 *///from  ww w  . j a va 2 s  . co m
public DescriptionTextRule() throws Exception {

    super(Node.DOCUMENT_FRAGMENT_NODE);

}

From source file:fr.gouv.finances.dgfip.xemelios.utils.XmlUtils.java

public static String getXmlDataSubstituteNode(Node node, String substituteWith, String substituteInWhat) {
    StringBuilder sb = new StringBuilder();
    switch (node.getNodeType()) {
    case Node.COMMENT_NODE:
    case Node.ENTITY_NODE:
    case Node.ENTITY_REFERENCE_NODE:
    case Node.NOTATION_NODE:
    case Node.PROCESSING_INSTRUCTION_NODE:
        break;//from   w w w .j  a  v  a  2s.c om
    case Node.DOCUMENT_NODE:
    case Node.DOCUMENT_FRAGMENT_NODE:
    case Node.ELEMENT_NODE: {
        String nodeName = node.getNodeName();
        if (!substituteInWhat.equals(nodeName)) {
            sb.append("<").append(nodeName);
            StringBuilder attrs = new StringBuilder();
            StringBuilder children = new StringBuilder();
            NamedNodeMap nnm = node.getAttributes();
            if (nnm != null) {
                for (int i = 0; i < nnm.getLength(); i++) {
                    Node attr = nnm.item(i);
                    attrs.append(" ").append(getXmlDataSubstituteNode(attr, substituteWith, substituteInWhat));
                }
            }
            NodeList nl = node.getChildNodes();
            if (nl != null) {
                for (int i = 0; i < nl.getLength(); i++) {
                    Node child = nl.item(i);
                    if (child.getNodeType() == Node.ATTRIBUTE_NODE) {
                        attrs.append(" ")
                                .append(getXmlDataSubstituteNode(child, substituteWith, substituteInWhat));
                    } else {
                        children.append(getXmlDataSubstituteNode(child, substituteWith, substituteInWhat));
                    }
                }
            }
            sb.append(attrs.toString());
            if (children.length() > 0) {
                sb.append(">").append(children.toString()).append("</").append(nodeName).append(">");
            } else {
                sb.append("/>");
            }
        } else {
            sb.append(substituteWith);
        }
        break;
    }
    case Node.ATTRIBUTE_NODE: {
        sb.append(node.getNodeName()).append("=\"").append(StringEscapeUtils.escapeXml(node.getNodeValue()))
                .append("\"");
        break;
    }
    case Node.CDATA_SECTION_NODE: {
        sb.append("<![CDATA[").append(StringEscapeUtils.escapeXml(node.getNodeValue())).append("]]>");
    }
    case Node.TEXT_NODE: {
        sb.append(StringEscapeUtils.escapeXml(node.getNodeValue()));
    }
    }
    return sb.toString();
}

From source file:Main.java

public final static Class<? extends Node> toClass(final short nodeType) {
    switch (nodeType) {
    case Node.ATTRIBUTE_NODE:
        return Attr.class;
    case Node.CDATA_SECTION_NODE:
        return CDATASection.class;
    case Node.COMMENT_NODE:
        return Comment.class;
    case Node.DOCUMENT_FRAGMENT_NODE:
        return DocumentFragment.class;
    case Node.DOCUMENT_NODE:
        return Document.class;
    case Node.DOCUMENT_TYPE_NODE:
        return DocumentType.class;
    case Node.ELEMENT_NODE:
        return Element.class;
    case Node.ENTITY_NODE:
        return Entity.class;
    case Node.ENTITY_REFERENCE_NODE:
        return EntityReference.class;
    case Node.NOTATION_NODE:
        return Notation.class;
    case Node.PROCESSING_INSTRUCTION_NODE:
        return ProcessingInstruction.class;
    case Node.TEXT_NODE:
        return Text.class;
    }//w ww. j  a v  a 2s  .  c o m
    throw new RuntimeException("Unrecognized node type " + nodeType);
}