/** * <p>Returns the canonical XPath expression which identifies this node, for instance * <tt>"/html/body/table[3]/tbody/tr[5]/td[2]/span/a[3]"</tt>.</p> * * <p><span style="color:red">WARNING:</span> This sort of automated XPath expression * is often quite bad at identifying a node, as it is highly sensitive to changes in * the DOM tree.</p> * * @return the canonical XPath expression which identifies this node * @see #getByXPath(String) */ public String getCanonicalXPath() { throw new RuntimeException("Method getCanonicalXPath() not implemented for nodes of type " + getNodeType()); }
/** * <p>Returns the canonical XPath expression which identifies this node, for instance * <tt>"/html/body/table[3]/tbody/tr[5]/td[2]/span/a[3]"</tt>.</p> * * <p><span style="color:red">WARNING:</span> This sort of automated XPath expression * is often quite bad at identifying a node, as it is highly sensitive to changes in * the DOM tree.</p> * * @return the canonical XPath expression which identifies this node * @see #getByXPath(String) */ public String getCanonicalXPath() { throw new RuntimeException("Method getCanonicalXPath() not implemented for nodes of type " + getNodeType()); }
/** * Gets the JavaScript property "nodeType" for the current node. * @return the node type */ public short jsxGet_nodeType() { return this.<DomNode>getDomNodeOrDie().getNodeType(); }
StringBuffer sb = new StringBuffer(/*some appropriate size*/); for (DomNode n : element.getChildNodes()) { if (n.getNodeType() == Node.TEXT_NODE) { sb.append(n.getTextContent()); } } String text = sb.toString();
/** * Gets the JavaScript property "nodeType" for the current node. * @return the node type */ public short jsxGet_nodeType() { return getDomNodeOrDie().getNodeType(); }
/** * Gets the JavaScript property "nodeType" for the current node. * @return the node type */ public short jsxGet_nodeType() { return getDomNodeOrDie().getNodeType(); }
/** * Gets the JavaScript property "nodeType" for the current node. * @return the node type */ public short jsxGet_nodeType() { return getDomNodeOrDie().getNodeType(); }
/** * Returns the XML Document Object Model (DOM) node type, which determines valid values and whether the node can * have child nodes. * @return the XML Document Object Model (DOM) node type */ @JsxGetter public short getNodeType() { final DomNode domNode = getDomNodeOrDie(); return domNode.getNodeType(); }
/** * Gets the JavaScript property {@code nodeType} for the current node. * @return the node type */ @JsxGetter public short getNodeType() { return getDomNodeOrDie().getNodeType(); }
/** * Returns the XML Document Object Model (DOM) node type, which determines valid values and whether the node can * have child nodes. * @return the XML Document Object Model (DOM) node type */ @JsxGetter public short getNodeType() { final DomNode domNode = getDomNodeOrDie(); return domNode.getNodeType(); }
/** * {@inheritDoc} */ @Override public String getTextContent() { switch (getNodeType()) { case ELEMENT_NODE: case ATTRIBUTE_NODE: case ENTITY_NODE: case ENTITY_REFERENCE_NODE: case DOCUMENT_FRAGMENT_NODE: final StringBuilder builder = new StringBuilder(); for (final DomNode child : getChildren()) { final short childType = child.getNodeType(); if (childType != COMMENT_NODE && childType != PROCESSING_INSTRUCTION_NODE) { builder.append(child.getTextContent()); } } return builder.toString(); case TEXT_NODE: case CDATA_SECTION_NODE: case COMMENT_NODE: case PROCESSING_INSTRUCTION_NODE: return getNodeValue(); default: return null; } }
/** * Gets the JavaScript property {@code nodeType} for the current node. * @return the node type */ @JsxGetter public short getNodeType() { return getDomNodeOrDie().getNodeType(); }
private void toText(final DomNode node, final StringBuilder buffer) { switch (node.getNodeType()) { case org.w3c.dom.Node.DOCUMENT_TYPE_NODE: case org.w3c.dom.Node.NOTATION_NODE: return; case org.w3c.dom.Node.TEXT_NODE: case org.w3c.dom.Node.CDATA_SECTION_NODE: case org.w3c.dom.Node.COMMENT_NODE: case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE: buffer.append(node.getNodeValue()); break; default: } for (final DomNode child : node.getChildren()) { switch (child.getNodeType()) { case org.w3c.dom.Node.ELEMENT_NODE: toText(child, buffer); break; case org.w3c.dom.Node.TEXT_NODE: case org.w3c.dom.Node.CDATA_SECTION_NODE: buffer.append(child.getNodeValue()); break; default: } } }
/** * {@inheritDoc} */ @Override public String getCanonicalXPath() { final DomNode parent = getParentNode(); if (parent.getNodeType() == DOCUMENT_NODE) { return "/" + getNodeName(); } return parent.getCanonicalXPath() + '/' + getXPathToken(); }
/** * {@inheritDoc} */ @Override public String getCanonicalXPath() { final DomNode parent = getParentNode(); if (parent.getNodeType() == DOCUMENT_NODE) { return "/" + getNodeName(); } return parent.getCanonicalXPath() + '/' + getXPathToken(); }
/** * Returns the XPath token for this node only. */ private String getXPathToken() { final DomNode parent = getParentNode(); int total = 0; int nodeIndex = 0; for (final DomNode child : parent.getChildren()) { if (child.getNodeType() == ELEMENT_NODE && child.getNodeName().equals(getNodeName())) { total++; } if (child == this) { nodeIndex = total; } } if (nodeIndex == 1 && total == 1) { return getNodeName(); } return getNodeName() + '[' + nodeIndex + ']'; }
/** * Returns the XPath token for this node only. */ private String getXPathToken() { final DomNode parent = getParentNode(); int total = 0; int nodeIndex = 0; for (final DomNode child : parent.getChildren()) { if (child.getNodeType() == ELEMENT_NODE && child.getNodeName().equals(getNodeName())) { total++; } if (child == this) { nodeIndex = total; } } if (nodeIndex == 1 && total == 1) { return getNodeName(); } return getNodeName() + '[' + nodeIndex + ']'; }
/** * Evaluates an XPath expression to an XObject. * @param contextNode the node to start searching from * @param str a valid XPath string * @return an XObject, which can be used to obtain a string, number, nodelist, etc (should never be <tt>null</tt>) * @throws TransformerException if a syntax or other error occurs */ private static XObject evaluateXPath(final DomNode contextNode, final String str) throws TransformerException { final XPathContext xpathSupport = new XPathContext(); final Node xpathExpressionContext; if (contextNode.getNodeType() == Node.DOCUMENT_NODE) { xpathExpressionContext = ((Document) contextNode).getDocumentElement(); } else { xpathExpressionContext = contextNode; } final PrefixResolver prefixResolver = new HtmlUnitPrefixResolver(xpathExpressionContext); final boolean caseSensitive = contextNode.getPage().hasCaseSensitiveTagNames(); final XPathAdapter xpath = new XPathAdapter(str, null, prefixResolver, null, caseSensitive); final int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); return xpath.execute(xpathSupport, ctxtNode, prefixResolver); }
/** * Evaluates an XPath expression to an XObject. * @param contextNode the node to start searching from * @param str a valid XPath string * @return an XObject, which can be used to obtain a string, number, nodelist, etc (should never be <tt>null</tt>) * @throws TransformerException if a syntax or other error occurs */ private static XObject evaluateXPath(final DomNode contextNode, final String str) throws TransformerException { final XPathContext xpathSupport = new XPathContext(); final Node xpathExpressionContext; if (contextNode.getNodeType() == Node.DOCUMENT_NODE) { xpathExpressionContext = ((Document) contextNode).getDocumentElement(); } else { xpathExpressionContext = contextNode; } final PrefixResolver prefixResolver = new HtmlUnitPrefixResolver(xpathExpressionContext); final boolean caseSensitive = contextNode.getPage().hasCaseSensitiveTagNames(); final XPathAdapter xpath = new XPathAdapter(str, null, prefixResolver, null, caseSensitive); final int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); return xpath.execute(xpathSupport, ctxtNode, prefixResolver); }
/** * Evaluates an XPath expression to an XObject. * @param contextNode the node to start searching from * @param str a valid XPath string * @return an XObject, which can be used to obtain a string, number, nodelist, etc (should never be <tt>null</tt>) * @throws TransformerException if a syntax or other error occurs */ private static XObject evaluateXPath(final DomNode contextNode, final String str) throws TransformerException { final XPathContext xpathSupport = new XPathContext(); final Node xpathExpressionContext; if (contextNode.getNodeType() == Node.DOCUMENT_NODE) { xpathExpressionContext = ((Document) contextNode).getDocumentElement(); } else { xpathExpressionContext = contextNode; } final PrefixResolver prefixResolver = new HtmlUnitPrefixResolver(xpathExpressionContext); final boolean caseSensitive = contextNode.getPage().hasCaseSensitiveTagNames(); final XPathAdapter xpath = new XPathAdapter(str, null, prefixResolver, null, caseSensitive); final int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); return xpath.execute(xpathSupport, ctxtNode, prefixResolver); }