/** * Method getElementById * * @param doc the document * @param id the value of the ID * @return the element obtained by the id, or null if it is not found. */ public static Element getElementById(Document doc, String id) { return doc.getElementById(id); }
/** * Given an XML ID, return the element. This requires assistance from the * DOM and parser, and is meaningful only in the context of a DTD * or schema which declares attributes as being of type ID. This * information may or may not be available in all parsers, may or * may not be available for specific documents, and may or may not * be available when validation is not turned on. * * @param id The ID to search for, as a String. * @param doc The document to search within, as a DOM Document node. * @return DOM Element node with an attribute of type ID whose value * uniquely matches the requested id string, or null if there isn't * such an element or if the DOM can't answer the question for other * reasons. */ public Element getElementByID(String id, Document doc) { return doc.getElementById(id); }
/** * Given an XML ID, return the element. This requires assistance from the * DOM and parser, and is meaningful only in the context of a DTD * or schema which declares attributes as being of type ID. This * information may or may not be available in all parsers, may or * may not be available for specific documents, and may or may not * be available when validation is not turned on. * * @param id The ID to search for, as a String. * @param doc The document to search within, as a DOM Document node. * @return DOM Element node with an attribute of type ID whose value * uniquely matches the requested id string, or null if there isn't * such an element or if the DOM can't answer the question for other * reasons. */ public Element getElementByID(String id, Document doc) { return doc.getElementById(id); }
File input = new File("/tmp/input.html"); Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/"); //http://jsoup.org/cookbook/input/load-document-from-url //Document doc = Jsoup.connect("http://example.com/").get(); Element content = doc.getElementById("content"); Elements links = content.getElementsByTag("a"); for (Element link : links) { String linkHref = link.attr("href"); String linkText = link.text(); }
Document doc; Element fooElem; doc = ...; // load XML document instance fooElem = ...; // locate the element node "foo" in doc fooElem.setIdAttribute("bar", true); // without this, 'found' would be null Element found = doc.getElementById("xyz");
EventListener listener = new EventListener() { public void handleEvent(Event ev) { Platform.exit(); } }; Document doc = webEngine.getDocument(); Element el = doc.getElementById("exit-app"); ((EventTarget) el).addEventListener("click", listener, false);
/** * Return the node identity for a given id String * * @param idString The id String * @return The identity of the node whose id is the given String. */ public int getElementById(String idString) { Node node = _document.getElementById(idString); if (node != null) { Integer id = (Integer)_node2Ids.get(node); return (id != null) ? id.intValue() : DTM.NULL; } else { return DTM.NULL; } }
/** * Returns the element whose ID is given by elementId. * If no such element exists, returns null. * Attributes with the name "ID" are not of type ID unless so defined. * Attribute types are only known if when the parser understands DTD's or * schemas that declare attributes of type ID. When JAXP is used, you * must call <code>setValidating(true)</code> on the * DocumentBuilderFactory. * * @param object a node from the document in which to look for the id * @param elementId id to look for * * @return element whose ID is given by elementId, or null if no such * element exists in the document or if the implementation * does not know about attribute types * @see javax.xml.parsers.DocumentBuilderFactory * * @throws ClassCastException if object is not an <code>org.w3c.dom.Node</code> object * */ public Object getElementById(Object object, String elementId) { Document doc = (Document)getDocumentNode(object); if (doc != null) return doc.getElementById(elementId); else return null; }
Node elem = doc.getElementById(elementId); if(null != elem)
Node elem = doc.getElementById(elementId); if(null != elem)
public DomElement getElementById(String id) { synchronized(document) { Element element = document.getElementById(id); if (element != null) { return new DomElementImpl(element); } else { return null; } } }
Document doc = Jsoup.parse(html); Element content = doc.getElementById("someid"); Elements p= content.getElementsByTag("p"); String pConcatenated=""; for (Element x: p) { pConcatenated+= x.text(); } System.out.println(pConcatenated);//sometext another p tag
/** * Method getElementById * * @param doc the document * @param id the value of the ID * @return the element obtained by the id, or null if it is not found. */ public static Element getElementById(Document doc, String id) { return doc.getElementById(id); }
/** * Method getElementById * * @param doc the document * @param id the value of the ID * @return the element obtained by the id, or null if it is not found. */ public static Element getElementById(Document doc, String id) { return doc.getElementById(id); }
/** * Returns the node referenced by the given fragment identifier. * This is called when the whole URI just contains a fragment identifier * and there is no XML Base URI in effect. * @param frag the URI fragment * @param ref the context element from which to resolve the URI fragment */ protected Node getNodeByFragment(String frag, Element ref) { return ref.getOwnerDocument().getElementById(frag); } }
public void operateOn(Document document) { Node node = document.getElementById(clientId); node.getParentNode().removeChild(node); } }
/** * Gets the first version set in the dictionaryconfig file for the given dictionary. This is useful when hitting an * error and wanting to get a fall back dictionary. This might error if there are no versions defined for the given * dictionary (or if the document is not valid) * * @param forDictionary * @return */ public static String getFirstVersion(String forDictionary) { return dictionaryConfig.getElementById(forDictionary).getFirstChild().getAttributes().getNamedItem("key") .getNodeValue(); }
// Only one line to parse an external content Document doc = Jsoup.connect("http://jsoup.org").get(); // "Javascript-like" syntax Element content = doc.getElementById("content"); Elements links = content.getElementsByTag("a"); for (Element link : links) { String linkHref = link.attr("href"); String linkText = link.text(); } // "Jquery/Css-like" syntax Elements resultLinks = doc.select("h3.r > a"); Elements pngs = doc.select("img[src$=.png]");
/** * @param type the name of the syntaxelement to be returned * @param document the structure containing the current syntaxdefinition * @return a XML-node with the definition of the requested syntaxelement */ public final Node getSyntaxDef(String type, Document document) { Node ret = document.getElementById(type); if (ret == null) throw new org.kapott.hbci.exceptions.NoSuchElementException(getElementTypeName(), type); return ret; }
public IUserLayoutNodeDescription getNode(String nodeId) throws PortalException { Document ulm = this.getUserLayoutDOM(); if (ulm == null) { throw new PortalException("UserLayout has not been initialized."); } // find an element with a given id Element element = (Element)ulm.getElementById(nodeId); if (element == null) { throw new PortalException("Element with ID=\"" + nodeId + "\" doesn't exist."); } return UserLayoutNodeDescription.createUserLayoutNodeDescription(element); }