Java Code Examples for org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE

The following are Jave code examples for showing how to use DOCUMENT_FRAGMENT_NODE of the org.w3c.dom.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: openjdk-jdk10   File: RangeImpl.java   Source Code and License Vote up 6 votes
/**
 * Returns true IFF the given node can be contained by
 * a range.
 */
private boolean isLegalContainedNode( Node node )
{
        if ( node==null )
                return false;
        switch( node.getNodeType() )
        {
        case Node.DOCUMENT_NODE:
        case Node.DOCUMENT_FRAGMENT_NODE:
        case Node.ATTRIBUTE_NODE:
        case Node.ENTITY_NODE:
        case Node.NOTATION_NODE:
                return false;
        }
        return true;
}
 
Example 2
Project: openjdk-jdk10   File: RangeImpl.java   Source Code and License Vote up 6 votes
/**
 * Finds the root container for the given node and determines
 * if that root container is legal with respect to the
 * DOM 2 specification.  At present, that means the root
 * container must be either an attribute, a document,
 * or a document fragment.
 */
private boolean hasLegalRootContainer( Node node )
{
        if ( node==null )
                return false;

        Node rootContainer = getRootContainer( node );
        switch( rootContainer.getNodeType() )
        {
        case Node.ATTRIBUTE_NODE:
        case Node.DOCUMENT_NODE:
        case Node.DOCUMENT_FRAGMENT_NODE:
                return true;
        }
        return false;
}
 
Example 3
Project: OpenJSharp   File: RangeImpl.java   Source Code and License Vote up 6 votes
/**
 * Finds the root container for the given node and determines
 * if that root container is legal with respect to the
 * DOM 2 specification.  At present, that means the root
 * container must be either an attribute, a document,
 * or a document fragment.
 */
private boolean hasLegalRootContainer( Node node )
{
        if ( node==null )
                return false;

        Node rootContainer = getRootContainer( node );
        switch( rootContainer.getNodeType() )
        {
        case Node.ATTRIBUTE_NODE:
        case Node.DOCUMENT_NODE:
        case Node.DOCUMENT_FRAGMENT_NODE:
                return true;
        }
        return false;
}
 
Example 4
Project: OpenJSharp   File: RangeImpl.java   Source Code and License Vote up 6 votes
/**
 * Returns true IFF the given node can be contained by
 * a range.
 */
private boolean isLegalContainedNode( Node node )
{
        if ( node==null )
                return false;
        switch( node.getNodeType() )
        {
        case Node.DOCUMENT_NODE:
        case Node.DOCUMENT_FRAGMENT_NODE:
        case Node.ATTRIBUTE_NODE:
        case Node.ENTITY_NODE:
        case Node.NOTATION_NODE:
                return false;
        }
        return true;
}
 
Example 5
Project: OpenJSharp   File: DOMPrinter.java   Source Code and License Vote up 5 votes
public void print(Node node) throws XMLStreamException {
    switch (node.getNodeType()) {
    case Node.DOCUMENT_NODE:
        visitDocument((Document) node);
        break;
    case Node.DOCUMENT_FRAGMENT_NODE:
        visitDocumentFragment((DocumentFragment) node);
        break;
    case Node.ELEMENT_NODE:
        visitElement((Element) node);
        break;
    case Node.TEXT_NODE:
        visitText((Text) node);
        break;
    case Node.CDATA_SECTION_NODE:
        visitCDATASection((CDATASection) node);
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        visitProcessingInstruction((ProcessingInstruction) node);
        break;
    case Node.ENTITY_REFERENCE_NODE:
        visitReference((EntityReference) node);
        break;
    case Node.COMMENT_NODE:
        visitComment((Comment) node);
        break;
    case Node.DOCUMENT_TYPE_NODE:
        break;
    case Node.ATTRIBUTE_NODE:
    case Node.ENTITY_NODE:
    default:
        throw new XMLStreamException("Unexpected DOM Node Type "
            + node.getNodeType()
        );
    }
}
 
Example 6
Project: openjdk-jdk10   File: DOM2DTM.java   Source Code and License Vote up 5 votes
/**
 * Retrieve the text content of a DOM subtree, appending it into a
 * user-supplied FastStringBuffer object. Note that attributes are
 * not considered part of the content of an element.
 * <p>
 * There are open questions regarding whitespace stripping.
 * Currently we make no special effort in that regard, since the standard
 * DOM doesn't yet provide DTD-based information to distinguish
 * whitespace-in-element-context from genuine #PCDATA. Note that we
 * should probably also consider xml:space if/when we address this.
 * DOM Level 3 may solve the problem for us.
 * <p>
 * %REVIEW% Actually, since this method operates on the DOM side of the
 * fence rather than the DTM side, it SHOULDN'T do
 * any special handling. The DOM does what the DOM does; if you want
 * DTM-level abstractions, use DTM-level methods.
 *
 * @param node Node whose subtree is to be walked, gathering the
 * contents of all Text or CDATASection nodes.
 * @param buf FastStringBuffer into which the contents of the text
 * nodes are to be concatenated.
 */
protected static void getNodeData(Node node, FastStringBuffer 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())
    {
      getNodeData(child, buf);
    }
  }
  break;
  case Node.TEXT_NODE :
  case Node.CDATA_SECTION_NODE :
  case Node.ATTRIBUTE_NODE :  // Never a child but might be our starting node
    buf.append(node.getNodeValue());
    break;
  case Node.PROCESSING_INSTRUCTION_NODE :
    // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
    break;
  default :
    // ignore
    break;
  }
}
 
Example 7
Project: OpenJSharp   File: DOMHelper.java   Source Code and License Vote up 5 votes
/**
 * Retrieve the text content of a DOM subtree, appending it into a
 * user-supplied FastStringBuffer object. Note that attributes are
 * not considered part of the content of an element.
 * <p>
 * There are open questions regarding whitespace stripping.
 * Currently we make no special effort in that regard, since the standard
 * DOM doesn't yet provide DTD-based information to distinguish
 * whitespace-in-element-context from genuine #PCDATA. Note that we
 * should probably also consider xml:space if/when we address this.
 * DOM Level 3 may solve the problem for us.
 *
 * @param node Node whose subtree is to be walked, gathering the
 * contents of all Text or CDATASection nodes.
 * @param buf FastStringBuffer into which the contents of the text
 * nodes are to be concatenated.
 */
public static void getNodeData(Node node, FastStringBuffer 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())
    {
      getNodeData(child, buf);
    }
  }
  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;
  }
}
 
Example 8
Project: OpenJSharp   File: DOM2DTM.java   Source Code and License Vote up 5 votes
/**
 * Retrieve the text content of a DOM subtree, appending it into a
 * user-supplied FastStringBuffer object. Note that attributes are
 * not considered part of the content of an element.
 * <p>
 * There are open questions regarding whitespace stripping.
 * Currently we make no special effort in that regard, since the standard
 * DOM doesn't yet provide DTD-based information to distinguish
 * whitespace-in-element-context from genuine #PCDATA. Note that we
 * should probably also consider xml:space if/when we address this.
 * DOM Level 3 may solve the problem for us.
 * <p>
 * %REVIEW% Actually, since this method operates on the DOM side of the
 * fence rather than the DTM side, it SHOULDN'T do
 * any special handling. The DOM does what the DOM does; if you want
 * DTM-level abstractions, use DTM-level methods.
 *
 * @param node Node whose subtree is to be walked, gathering the
 * contents of all Text or CDATASection nodes.
 * @param buf FastStringBuffer into which the contents of the text
 * nodes are to be concatenated.
 */
protected static void getNodeData(Node node, FastStringBuffer 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())
    {
      getNodeData(child, buf);
    }
  }
  break;
  case Node.TEXT_NODE :
  case Node.CDATA_SECTION_NODE :
  case Node.ATTRIBUTE_NODE :  // Never a child but might be our starting node
    buf.append(node.getNodeValue());
    break;
  case Node.PROCESSING_INSTRUCTION_NODE :
    // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
    break;
  default :
    // ignore
    break;
  }
}
 
Example 9
Project: openjdk-jdk10   File: DOM2DTM.java   Source Code and License Vote up 4 votes
/**
   * Retrieve the text content of a DOM subtree, appending it into a
   * user-supplied FastStringBuffer object. Note that attributes are
   * not considered part of the content of an element.
   * <p>
   * There are open questions regarding whitespace stripping.
   * Currently we make no special effort in that regard, since the standard
   * DOM doesn't yet provide DTD-based information to distinguish
   * whitespace-in-element-context from genuine #PCDATA. Note that we
   * should probably also consider xml:space if/when we address this.
   * DOM Level 3 may solve the problem for us.
   * <p>
   * %REVIEW% Note that as a DOM-level operation, it can be argued that this
   * routine _shouldn't_ perform any processing beyond what the DOM already
   * does, and that whitespace stripping and so on belong at the DTM level.
   * If you want a stripped DOM view, wrap DTM2DOM around DOM2DTM.
   *
   * @param node Node whose subtree is to be walked, gathering the
   * contents of all Text or CDATASection nodes.
   */
  protected static void dispatchNodeData(Node node,
                                         org.xml.sax.ContentHandler ch,
                                         int depth)
            throws org.xml.sax.SAXException
  {

    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())
      {
        dispatchNodeData(child, ch, depth+1);
      }
    }
    break;
    case Node.PROCESSING_INSTRUCTION_NODE : // %REVIEW%
    case Node.COMMENT_NODE :
      if(0 != depth)
        break;
        // NOTE: Because this operation works in the DOM space, it does _not_ attempt
        // to perform Text Coalition. That should only be done in DTM space.
    case Node.TEXT_NODE :
    case Node.CDATA_SECTION_NODE :
    case Node.ATTRIBUTE_NODE :
      String str = node.getNodeValue();
      if(ch instanceof CharacterNodeHandler)
      {
        ((CharacterNodeHandler)ch).characters(node);
      }
      else
      {
        ch.characters(str.toCharArray(), 0, str.length());
      }
      break;
//    /* case Node.PROCESSING_INSTRUCTION_NODE :
//      // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
//      break; */
    default :
      // ignore
      break;
    }
  }
 
Example 10
Project: openjdk-jdk10   File: DOM2DTMdefaultNamespaceDeclarationNode.java   Source Code and License Vote up 4 votes
/**
     *
     * DOM Level 3 - Experimental:
     * Look up the prefix associated to the given namespace URI, starting from this node.
     *
     * @param namespaceURI
     * @return the prefix for the namespace
     */
    public String lookupPrefix(String namespaceURI){

        // REVISIT: When Namespaces 1.1 comes out this may not be true
        // Prefix can't be bound to null namespace
        if (namespaceURI == null) {
            return null;
        }

        short type = this.getNodeType();

        switch (type) {
/*
        case Node.ELEMENT_NODE: {

                String namespace = this.getNamespaceURI(); // to flip out children
                return lookupNamespacePrefix(namespaceURI, (ElementImpl)this);
            }

        case Node.DOCUMENT_NODE:{
                return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI);
            }
*/
        case Node.ENTITY_NODE :
        case Node.NOTATION_NODE:
        case Node.DOCUMENT_FRAGMENT_NODE:
        case Node.DOCUMENT_TYPE_NODE:
            // type is unknown
            return null;
        case Node.ATTRIBUTE_NODE:{
                if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) {
                    return getOwnerElement().lookupPrefix(namespaceURI);

                }
                return null;
            }
        default:{
/*
                NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
                if (ancestor != null) {
                    return ancestor.lookupPrefix(namespaceURI);
                }
*/
                return null;
            }
         }
    }
 
Example 11
Project: convertigo-engine   File: TwsDomTreeWrap.java   Source Code and License Vote up 4 votes
private static void addNodeInTree2(Node node, Document document, Element parent, int [] index) {
    Element currentElement = createElement2(document, node, index);
    currentElement.setAttribute("type", Short.toString(node.getNodeType()));

    switch (node.getNodeType()) {
        case Node.ELEMENT_NODE:
            currentElement.setAttribute("text", node.getNodeName());
            NamedNodeMap map = node.getAttributes();
            if (node.hasAttributes()) {
                Element attributes = createElement2(document, node, index);
                attributes.setAttribute("text", "Attributes");
                attributes.setAttribute("type", Short.toString(Node.ATTRIBUTE_NODE));
                currentElement.appendChild(attributes);

                for (int i = 0; i < map.getLength(); ++i) {
                    Element attribute = createElement2(document, map.item(i), index);
                    attribute.setAttribute("text", map.item(i).getNodeName() + "=\"" + map.item(i).getNodeValue() + "\"");
                    attribute.setAttribute("type", Short.toString(Node.ATTRIBUTE_NODE));
                    attributes.appendChild(attribute);
                }
            }
            break;

        case Node.TEXT_NODE:
            currentElement.setAttribute("text", node.getNodeValue() == null ? "" : node.getNodeValue().trim());
            break;

        case Node.ENTITY_NODE:
            currentElement.setAttribute("text", "[Entity]");
            break;

        case Node.ENTITY_REFERENCE_NODE:
            currentElement.setAttribute("text", "[Entityref]");
            break;

        case Node.PROCESSING_INSTRUCTION_NODE:
            currentElement.setAttribute("text", "[Pi]");
            break;

        case Node.COMMENT_NODE:
            currentElement.setAttribute("text", "[Comment]");
            break;

        case Node.DOCUMENT_FRAGMENT_NODE:
            currentElement.setAttribute("text", "[Docfgmt]");
            break;

        case Node.DOCUMENT_TYPE_NODE:
            currentElement.setAttribute("text", "[Doctype]");
            break;

        case Node.NOTATION_NODE:
            currentElement.setAttribute("text", "[Notation]");
            break;

        default:
            break;
    }
    parent.appendChild(currentElement);

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node currentNode = nodeList.item(i);
        addNodeInTree2(currentNode, document, currentElement, index);
    }
}
 
Example 12
Project: openjdk-jdk10   File: DTMNodeProxy.java   Source Code and License Vote up 4 votes
/**
     *
     * DOM Level 3
     * Look up the prefix associated to the given namespace URI, starting from this node.
     *
     * @param namespaceURI
     * @return the prefix for the namespace
     */
    @Override
    public String lookupPrefix(String namespaceURI){

        // REVISIT: When Namespaces 1.1 comes out this may not be true
        // Prefix can't be bound to null namespace
        if (namespaceURI == null) {
            return null;
        }

        short type = this.getNodeType();

        switch (type) {
/*
        case Node.ELEMENT_NODE: {

                String namespace = this.getNamespaceURI(); // to flip out children
                return lookupNamespacePrefix(namespaceURI, (ElementImpl)this);
            }

        case Node.DOCUMENT_NODE:{
                return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI);
            }
*/
        case Node.ENTITY_NODE :
        case Node.NOTATION_NODE:
        case Node.DOCUMENT_FRAGMENT_NODE:
        case Node.DOCUMENT_TYPE_NODE:
            // type is unknown
            return null;
        case Node.ATTRIBUTE_NODE:{
                if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) {
                    return getOwnerElement().lookupPrefix(namespaceURI);

                }
                return null;
            }
        default:{
/*
                NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
                if (ancestor != null) {
                    return ancestor.lookupPrefix(namespaceURI);
                }
*/
                return null;
            }
         }
    }
 
Example 13
Project: OpenJSharp   File: UnImplNode.java   Source Code and License Vote up 4 votes
/**
     *
     * DOM Level 3 - Experimental:
     * Look up the prefix associated to the given namespace URI, starting from this node.
     *
     * @param namespaceURI
     * @return the prefix for the namespace
     */
    public String lookupPrefix(String namespaceURI){

        // REVISIT: When Namespaces 1.1 comes out this may not be true
        // Prefix can't be bound to null namespace
        if (namespaceURI == null) {
            return null;
        }

        short type = this.getNodeType();

        switch (type) {
/*
        case Node.ELEMENT_NODE: {

                String namespace = this.getNamespaceURI(); // to flip out children
                return lookupNamespacePrefix(namespaceURI, (ElementImpl)this);
            }

        case Node.DOCUMENT_NODE:{
                return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI);
            }
*/
        case Node.ENTITY_NODE :
        case Node.NOTATION_NODE:
        case Node.DOCUMENT_FRAGMENT_NODE:
        case Node.DOCUMENT_TYPE_NODE:
            // type is unknown
            return null;
        case Node.ATTRIBUTE_NODE:{
                if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) {
                    return getOwnerElement().lookupPrefix(namespaceURI);

                }
                return null;
            }
        default:{
/*
                NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
                if (ancestor != null) {
                    return ancestor.lookupPrefix(namespaceURI);
                }
*/
                return null;
            }
         }
    }
 
Example 14
Project: openjdk-jdk10   File: UnImplNode.java   Source Code and License Vote up 4 votes
/**
     *
     * DOM Level 3 - Experimental:
     * Look up the prefix associated to the given namespace URI, starting from this node.
     *
     * @param namespaceURI
     * @return the prefix for the namespace
     */
    public String lookupPrefix(String namespaceURI){

        // REVISIT: When Namespaces 1.1 comes out this may not be true
        // Prefix can't be bound to null namespace
        if (namespaceURI == null) {
            return null;
        }

        short type = this.getNodeType();

        switch (type) {
/*
        case Node.ELEMENT_NODE: {

                String namespace = this.getNamespaceURI(); // to flip out children
                return lookupNamespacePrefix(namespaceURI, (ElementImpl)this);
            }

        case Node.DOCUMENT_NODE:{
                return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI);
            }
*/
        case Node.ENTITY_NODE :
        case Node.NOTATION_NODE:
        case Node.DOCUMENT_FRAGMENT_NODE:
        case Node.DOCUMENT_TYPE_NODE:
            // type is unknown
            return null;
        case Node.ATTRIBUTE_NODE:{
                if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) {
                    return getOwnerElement().lookupPrefix(namespaceURI);

                }
                return null;
            }
        default:{
/*
                NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
                if (ancestor != null) {
                    return ancestor.lookupPrefix(namespaceURI);
                }
*/
                return null;
            }
         }
    }
 
Example 15
Project: tomcat7   File: NodeCreateRule.java   Source Code and License Vote up 3 votes
/**
 * Constructor. Creates an instance of this rule that will create either a 
 * DOM {@link org.w3c.dom.Element Element} or a DOM 
 * {@link org.w3c.dom.DocumentFragment DocumentFragment}, depending on the
 * value of the <code>nodeType</code> parameter. This constructor lets you
 * specify the JAXP <code>DocumentBuilder</code> that should be used when
 * constructing the node tree.
 * 
 * @param nodeType the type of node to create, which can be either
 *   {@link org.w3c.dom.Node#ELEMENT_NODE Node.ELEMENT_NODE} or 
 *   {@link org.w3c.dom.Node#DOCUMENT_FRAGMENT_NODE Node.DOCUMENT_FRAGMENT_NODE}
 * @param documentBuilder the JAXP <code>DocumentBuilder</code> to use
 * @throws IllegalArgumentException if the node type is not supported
 */
public NodeCreateRule(int nodeType, DocumentBuilder documentBuilder) {

    if (!((nodeType == Node.DOCUMENT_FRAGMENT_NODE) ||
          (nodeType == Node.ELEMENT_NODE))) {
        throw new IllegalArgumentException(
            "Can only create nodes of type DocumentFragment and Element");
    }
    this.nodeType = nodeType;
    this.documentBuilder = documentBuilder;

}
 
Example 16
Project: apache-tomcat-7.0.73-with-comment   File: NodeCreateRule.java   Source Code and License Vote up 3 votes
/**
 * Constructor. Creates an instance of this rule that will create either a 
 * DOM {@link org.w3c.dom.Element Element} or a DOM 
 * {@link org.w3c.dom.DocumentFragment DocumentFragment}, depending on the
 * value of the <code>nodeType</code> parameter. This constructor lets you
 * specify the JAXP <code>DocumentBuilder</code> that should be used when
 * constructing the node tree.
 * 
 * @param nodeType the type of node to create, which can be either
 *   {@link org.w3c.dom.Node#ELEMENT_NODE Node.ELEMENT_NODE} or 
 *   {@link org.w3c.dom.Node#DOCUMENT_FRAGMENT_NODE Node.DOCUMENT_FRAGMENT_NODE}
 * @param documentBuilder the JAXP <code>DocumentBuilder</code> to use
 * @throws IllegalArgumentException if the node type is not supported
 */
public NodeCreateRule(int nodeType, DocumentBuilder documentBuilder) {

    if (!((nodeType == Node.DOCUMENT_FRAGMENT_NODE) ||
          (nodeType == Node.ELEMENT_NODE))) {
        throw new IllegalArgumentException(
            "Can only create nodes of type DocumentFragment and Element");
    }
    this.nodeType = nodeType;
    this.documentBuilder = documentBuilder;

}
 
Example 17
Project: lazycat   File: NodeCreateRule.java   Source Code and License Vote up 3 votes
/**
 * Constructor. Creates an instance of this rule that will create either a
 * DOM {@link org.w3c.dom.Element Element} or a DOM
 * {@link org.w3c.dom.DocumentFragment DocumentFragment}, depending on the
 * value of the <code>nodeType</code> parameter. This constructor lets you
 * specify the JAXP <code>DocumentBuilder</code> that should be used when
 * constructing the node tree.
 * 
 * @param nodeType
 *            the type of node to create, which can be either
 *            {@link org.w3c.dom.Node#ELEMENT_NODE Node.ELEMENT_NODE} or
 *            {@link org.w3c.dom.Node#DOCUMENT_FRAGMENT_NODE
 *            Node.DOCUMENT_FRAGMENT_NODE}
 * @param documentBuilder
 *            the JAXP <code>DocumentBuilder</code> to use
 * @throws IllegalArgumentException
 *             if the node type is not supported
 */
public NodeCreateRule(int nodeType, DocumentBuilder documentBuilder) {

	if (!((nodeType == Node.DOCUMENT_FRAGMENT_NODE) || (nodeType == Node.ELEMENT_NODE))) {
		throw new IllegalArgumentException("Can only create nodes of type DocumentFragment and Element");
	}
	this.nodeType = nodeType;
	this.documentBuilder = documentBuilder;

}
 
Example 18
Project: OpenJSharp   File: DOMHelper.java   Source Code and License Vote up 3 votes
/**
 * Get the root node of the document tree, regardless of
 * whether or not the node passed in is a document node.
 * <p>
 * TODO: This doesn't handle DocumentFragments or "orphaned" subtrees
 * -- it's currently returning ownerDocument even when the tree is
 * not actually part of the main Document tree. We should either
 * rewrite the description to say that it finds the Document node,
 * or change the code to walk up the ancestor chain.

 *
 * @param n Node to be examined
 *
 * @return the Document node. Note that this is not the correct answer
 * if n was (or was a child of) a DocumentFragment or an orphaned node,
 * as can arise if the DOM has been edited rather than being generated
 * by a parser.
 */
public Node getRootNode(Node n)
{
  int nt = n.getNodeType();
  return ( (Node.DOCUMENT_NODE == nt) || (Node.DOCUMENT_FRAGMENT_NODE == nt) )
         ? n : n.getOwnerDocument();
}
 
Example 19
Project: OpenJSharp   File: DocumentFragmentImpl.java   Source Code and License Vote up 2 votes
/**
 * A short integer indicating what type of node this is. The named
 * constants for this value are defined in the org.w3c.dom.Node interface.
 */
public short getNodeType() {
    return Node.DOCUMENT_FRAGMENT_NODE;
}
 
Example 20
Project: openjdk-jdk10   File: DocumentFragmentImpl.java   Source Code and License Vote up 2 votes
/**
 * A short integer indicating what type of node this is. The named
 * constants for this value are defined in the org.w3c.dom.Node interface.
 */
public short getNodeType() {
    return Node.DOCUMENT_FRAGMENT_NODE;
}