org.w3c.dom.traversal.NodeIterator#nextNode ( )源码实例Demo

下面列出了org.w3c.dom.traversal.NodeIterator#nextNode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: JDKSourceCode1.8   文件: NodeSet.java
/**
 * Copy NodeList members into this nodelist, adding in
 * document order.  Null references are not added.
 *
 * @param iterator NodeIterator which yields the nodes to be added.
 * @throws RuntimeException thrown if this NodeSet is not of
 * a mutable type.
 */
public void addNodes(NodeIterator iterator)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  if (null != iterator)  // defensive to fix a bug that Sanjiva reported.
  {
    Node obj;

    while (null != (obj = iterator.nextNode()))
    {
      addElement(obj);
    }
  }

  // checkDups();
}
 
源代码2 项目: jdk1.8-source-analysis   文件: XPathAPI.java
/**
 * Use an XPath string to select a single node.
 * XPath namespace prefixes are resolved from the namespaceNode.
 *
 * @param contextNode The node to start searching from.
 * @param str A valid XPath string.
 * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 * @return The first node found that matches the XPath, or null.
 *
 * @throws TransformerException
 */
public static Node selectSingleNode(
        Node contextNode, String str, Node namespaceNode)
          throws TransformerException
{

  // Have the XObject return its result as a NodeSetDTM.
  NodeIterator nl = selectNodeIterator(contextNode, str, namespaceNode);

  // Return the first node, or null
  return nl.nextNode();
}
 
源代码3 项目: jdk1.8-source-analysis   文件: NodeSetDTM.java
/**
 * Create a NodeSetDTM, and copy the members of the
 * given DTMIterator into it.
 *
 * @param iterator Iterator which yields Nodes to be made members of the new set.
 */
public NodeSetDTM(NodeIterator iterator, XPathContext xctxt)
{

  super();

  Node node;
  m_manager = xctxt.getDTMManager();

  while (null != (node = iterator.nextNode()))
  {
    int handle = xctxt.getDTMHandleFromNode(node);
    addNodeInDocOrder(handle, xctxt);
  }
}
 
源代码4 项目: jdk1.8-source-analysis   文件: NodeSet.java
/**
 * Copy NodeList members into this nodelist, adding in
 * document order.  If a node is null, don't add it.
 *
 * @param iterator NodeIterator which yields the nodes to be added.
 * @param support The XPath runtime context.
 * @throws RuntimeException thrown if this NodeSet is not of
 * a mutable type.
 */
public void addNodesInDocOrder(NodeIterator iterator, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  Node node;

  while (null != (node = iterator.nextNode()))
  {
    addNodeInDocOrder(node, support);
  }
}
 
源代码5 项目: jdk8u60   文件: XPathResultImpl.java
/**
         * The value of this single node result, which may be <code>null</code>.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>ANY_UNORDERED_NODE_TYPE</code> or
     *   <code>FIRST_ORDERED_NODE_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
         */
        public Node getSingleNodeValue() throws XPathException {

                if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
                    (m_resultType != FIRST_ORDERED_NODE_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
//                               This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
            }

                NodeIterator result = null;
                try {
                        result = m_resultObj.nodeset();
                } catch (TransformerException te) {
                        throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
                }

        if (null == result) return null;

        Node node = result.nextNode();

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
private Object getResultAsType( XObject resultObject, QName returnType )
    throws javax.xml.transform.TransformerException {
    // XPathConstants.STRING
    if ( returnType.equals( XPathConstants.STRING ) ) {
        return resultObject.str();
    }
    // XPathConstants.NUMBER
    if ( returnType.equals( XPathConstants.NUMBER ) ) {
        return new Double ( resultObject.num());
    }
    // XPathConstants.BOOLEAN
    if ( returnType.equals( XPathConstants.BOOLEAN ) ) {
        return new Boolean( resultObject.bool());
    }
    // XPathConstants.NODESET ---ORdered, UNOrdered???
    if ( returnType.equals( XPathConstants.NODESET ) ) {
        return resultObject.nodelist();
    }
    // XPathConstants.NODE
    if ( returnType.equals( XPathConstants.NODE ) ) {
        NodeIterator ni = resultObject.nodeset();
        //Return the first node, or null
        return ni.nextNode();
    }
    // If isSupported check is already done then the execution path
    // shouldn't come here. Being defensive
    String fmsg = XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
            new Object[] { returnType.toString()});
    throw new IllegalArgumentException ( fmsg );
}
 
源代码7 项目: jdk1.8-source-analysis   文件: XPathResultImpl.java
/**
         * The value of this single node result, which may be <code>null</code>.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>ANY_UNORDERED_NODE_TYPE</code> or
     *   <code>FIRST_ORDERED_NODE_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
         */
        public Node getSingleNodeValue() throws XPathException {

                if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
                    (m_resultType != FIRST_ORDERED_NODE_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
//                               This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
            }

                NodeIterator result = null;
                try {
                        result = m_resultObj.nodeset();
                } catch (TransformerException te) {
                        throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
                }

        if (null == result) return null;

        Node node = result.nextNode();

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
源代码8 项目: jdk1.8-source-analysis   文件: CachedXPathAPI.java
/**
 * Use an XPath string to select a single node.
 * XPath namespace prefixes are resolved from the namespaceNode.
 *
 * @param contextNode The node to start searching from.
 * @param str A valid XPath string.
 * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 * @return The first node found that matches the XPath, or null.
 *
 * @throws TransformerException
 */
public  Node selectSingleNode(
        Node contextNode, String str, Node namespaceNode)
          throws TransformerException
{

  // Have the XObject return its result as a NodeSetDTM.
  NodeIterator nl = selectNodeIterator(contextNode, str, namespaceNode);

  // Return the first node, or null
  return nl.nextNode();
}
 
源代码9 项目: openjdk-jdk8u   文件: NodeSet.java
/**
 * Copy NodeList members into this nodelist, adding in
 * document order.  If a node is null, don't add it.
 *
 * @param iterator NodeIterator which yields the nodes to be added.
 * @param support The XPath runtime context.
 * @throws RuntimeException thrown if this NodeSet is not of
 * a mutable type.
 */
public void addNodesInDocOrder(NodeIterator iterator, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  Node node;

  while (null != (node = iterator.nextNode()))
  {
    addNodeInDocOrder(node, support);
  }
}
 
源代码10 项目: JDKSourceCode1.8   文件: NodeSetDTM.java
/**
 * Create a NodeSetDTM, and copy the members of the
 * given DTMIterator into it.
 *
 * @param iterator Iterator which yields Nodes to be made members of the new set.
 */
public NodeSetDTM(NodeIterator iterator, XPathContext xctxt)
{

  super();

  Node node;
  m_manager = xctxt.getDTMManager();

  while (null != (node = iterator.nextNode()))
  {
    int handle = xctxt.getDTMHandleFromNode(node);
    addNodeInDocOrder(handle, xctxt);
  }
}
 
源代码11 项目: JDKSourceCode1.8   文件: XPathImpl.java
private Object getResultAsType( XObject resultObject, QName returnType )
    throws javax.xml.transform.TransformerException {
    // XPathConstants.STRING
    if ( returnType.equals( XPathConstants.STRING ) ) {
        return resultObject.str();
    }
    // XPathConstants.NUMBER
    if ( returnType.equals( XPathConstants.NUMBER ) ) {
        return new Double ( resultObject.num());
    }
    // XPathConstants.BOOLEAN
    if ( returnType.equals( XPathConstants.BOOLEAN ) ) {
        return new Boolean( resultObject.bool());
    }
    // XPathConstants.NODESET ---ORdered, UNOrdered???
    if ( returnType.equals( XPathConstants.NODESET ) ) {
        return resultObject.nodelist();
    }
    // XPathConstants.NODE
    if ( returnType.equals( XPathConstants.NODE ) ) {
        NodeIterator ni = resultObject.nodeset();
        //Return the first node, or null
        return ni.nextNode();
    }
    String fmsg = XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
            new Object[] { returnType.toString()});
    throw new IllegalArgumentException( fmsg );
}
 
源代码12 项目: TencentKona-8   文件: NodeSet.java
/**
 * Copy NodeList members into this nodelist, adding in
 * document order.  If a node is null, don't add it.
 *
 * @param iterator NodeIterator which yields the nodes to be added.
 * @param support The XPath runtime context.
 * @throws RuntimeException thrown if this NodeSet is not of
 * a mutable type.
 */
public void addNodesInDocOrder(NodeIterator iterator, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  Node node;

  while (null != (node = iterator.nextNode()))
  {
    addNodeInDocOrder(node, support);
  }
}
 
源代码13 项目: JDKSourceCode1.8   文件: CachedXPathAPI.java
/**
 * Use an XPath string to select a single node.
 * XPath namespace prefixes are resolved from the namespaceNode.
 *
 * @param contextNode The node to start searching from.
 * @param str A valid XPath string.
 * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 * @return The first node found that matches the XPath, or null.
 *
 * @throws TransformerException
 */
public  Node selectSingleNode(
        Node contextNode, String str, Node namespaceNode)
          throws TransformerException
{

  // Have the XObject return its result as a NodeSetDTM.
  NodeIterator nl = selectNodeIterator(contextNode, str, namespaceNode);

  // Return the first node, or null
  return nl.nextNode();
}
 
源代码14 项目: jdk8u60   文件: CachedXPathAPI.java
/**
 * Use an XPath string to select a single node.
 * XPath namespace prefixes are resolved from the namespaceNode.
 *
 * @param contextNode The node to start searching from.
 * @param str A valid XPath string.
 * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 * @return The first node found that matches the XPath, or null.
 *
 * @throws TransformerException
 */
public  Node selectSingleNode(
        Node contextNode, String str, Node namespaceNode)
          throws TransformerException
{

  // Have the XObject return its result as a NodeSetDTM.
  NodeIterator nl = selectNodeIterator(contextNode, str, namespaceNode);

  // Return the first node, or null
  return nl.nextNode();
}
 
源代码15 项目: TencentKona-8   文件: XPathResultImpl.java
/**
         * The value of this single node result, which may be <code>null</code>.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>ANY_UNORDERED_NODE_TYPE</code> or
     *   <code>FIRST_ORDERED_NODE_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
         */
        public Node getSingleNodeValue() throws XPathException {

                if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
                    (m_resultType != FIRST_ORDERED_NODE_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
//                               This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
            }

                NodeIterator result = null;
                try {
                        result = m_resultObj.nodeset();
                } catch (TransformerException te) {
                        throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
                }

        if (null == result) return null;

        Node node = result.nextNode();

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
源代码16 项目: JDKSourceCode1.8   文件: XPathResultImpl.java
/**
         * The value of this single node result, which may be <code>null</code>.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>ANY_UNORDERED_NODE_TYPE</code> or
     *   <code>FIRST_ORDERED_NODE_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
         */
        public Node getSingleNodeValue() throws XPathException {

                if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
                    (m_resultType != FIRST_ORDERED_NODE_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
//                               This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
            }

                NodeIterator result = null;
                try {
                        result = m_resultObj.nodeset();
                } catch (TransformerException te) {
                        throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
                }

        if (null == result) return null;

        Node node = result.nextNode();

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
源代码17 项目: jdk8u60   文件: XPathAPI.java
/**
 * Use an XPath string to select a single node.
 * XPath namespace prefixes are resolved from the namespaceNode.
 *
 * @param contextNode The node to start searching from.
 * @param str A valid XPath string.
 * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 * @return The first node found that matches the XPath, or null.
 *
 * @throws TransformerException
 */
public static Node selectSingleNode(
        Node contextNode, String str, Node namespaceNode)
          throws TransformerException
{

  // Have the XObject return its result as a NodeSetDTM.
  NodeIterator nl = selectNodeIterator(contextNode, str, namespaceNode);

  // Return the first node, or null
  return nl.nextNode();
}
 
源代码18 项目: jdk8u60   文件: XPathImpl.java
private Object getResultAsType( XObject resultObject, QName returnType )
    throws javax.xml.transform.TransformerException {
    // XPathConstants.STRING
    if ( returnType.equals( XPathConstants.STRING ) ) {
        return resultObject.str();
    }
    // XPathConstants.NUMBER
    if ( returnType.equals( XPathConstants.NUMBER ) ) {
        return new Double ( resultObject.num());
    }
    // XPathConstants.BOOLEAN
    if ( returnType.equals( XPathConstants.BOOLEAN ) ) {
        return new Boolean( resultObject.bool());
    }
    // XPathConstants.NODESET ---ORdered, UNOrdered???
    if ( returnType.equals( XPathConstants.NODESET ) ) {
        return resultObject.nodelist();
    }
    // XPathConstants.NODE
    if ( returnType.equals( XPathConstants.NODE ) ) {
        NodeIterator ni = resultObject.nodeset();
        //Return the first node, or null
        return ni.nextNode();
    }
    String fmsg = XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
            new Object[] { returnType.toString()});
    throw new IllegalArgumentException( fmsg );
}
 
源代码19 项目: openjdk-jdk8u   文件: XPathResultImpl.java
/**
         * The value of this single node result, which may be <code>null</code>.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>ANY_UNORDERED_NODE_TYPE</code> or
     *   <code>FIRST_ORDERED_NODE_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
         */
        public Node getSingleNodeValue() throws XPathException {

                if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
                    (m_resultType != FIRST_ORDERED_NODE_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
//                               This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
            }

                NodeIterator result = null;
                try {
                        result = m_resultObj.nodeset();
                } catch (TransformerException te) {
                        throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
                }

        if (null == result) return null;

        Node node = result.nextNode();

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
源代码20 项目: jdk8u60   文件: NodeSet.java
/**
 * Copy NodeList members into this nodelist, adding in
 * document order.  If a node is null, don't add it.
 *
 * @param iterator NodeIterator which yields the nodes to be added.
 * @param support The XPath runtime context.
 * @throws RuntimeException thrown if this NodeSet is not of
 * a mutable type.
 */
public void addNodesInDocOrder(NodeIterator iterator, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  Node node;

  while (null != (node = iterator.nextNode()))
  {
    addNodeInDocOrder(node, support);
  }
}
 
 同类方法