public void configure(String pluginName) { try { SAXReader saxReader = new SAXReader(); saxReader.setEncoding("UTF-8"); Document cacheXml = saxReader.read(configDataStream); List<Node> mappings = cacheXml.selectNodes("/cache-config/cache-mapping"); for (Node mapping: mappings) { registerCache(pluginName, mapping); } } catch (DocumentException e) { Log.error(e.getMessage(), e); } }
return null; List<Node> nodes = document.selectNodes( document.getRootElement().getName() ); monitor.worked( 1 ); monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes" ) );
return null; List<Node> nodes = document.selectNodes( this.loopXPath ); monitor.worked( 1 ); monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes" ) );
private List<?> getMsgContents(String msgID) { List<?> nodes = msgContents.selectNodes("//dataroot/MsgContents[MsgID=" + msgID + "]"); nodes.sort(new MsgContentNodeComparator()); return nodes; }
private List<?> getMsgContents(String msgID) { List<?> nodes = msgContents.selectNodes("//dataroot/MsgContents[MsgID=" + msgID + "]"); Collections.sort(nodes, new MsgContentNodeComparator()); return nodes; }
SAXReader reader = new SAXReader(); // dom4j SAXReader Document document = reader.read(xmlInputStream); // dom4j Document // select all link nodes with href "http://example.com" List<Element> linkNodes = document.selectNodes("//link[@href='http://example.com']"); // select an attribute value String val = linkNodes.get(0).attributeValue("href"); // select element text and trim it String value = document.elementTextTrim("childNode");
/** * Parses the series based on the XML configuration. */ private void parseSeries() { Iterator it = doc.selectNodes("//serie-def").iterator(); while (it.hasNext()) { addSerie((Node) it.next()); } }
private List<?> getMsgContents(String msgID) { List<?> nodes = msgContents.selectNodes("//dataroot/MsgContents[MsgID=" + msgID + "]"); nodes.sort(new MsgContentNodeComparator()); return nodes; }
private List<?> getMsgContents(String msgID) { List<?> nodes = msgContents.selectNodes("//dataroot/MsgContents[MsgID=" + msgID + "]"); nodes.sort(new MsgContentNodeComparator()); return nodes; }
/** * Makes sure that <label for=...> is not used inside config.jelly nor global.jelly */ private void checkLabelFor(Document dom) { if (isConfigJelly() || isGlobalJelly()) { if (!dom.selectNodes("//label[@for]").isEmpty()) throw new AssertionError("<label for=...> shouldn't be used because it doesn't work " + "when the configuration item is repeated. Use <label class=\"attach-previous\"> " + "to have your label attach to the previous DOM node instead."); } }
/** * Makes sure that <label for=...> is not used inside config.jelly nor global.jelly */ private void checkLabelFor(Document dom) { if (isConfigJelly() || isGlobalJelly()) { if (!dom.selectNodes("//label[@for]").isEmpty()) throw new AssertionError("<label for=...> shouldn't be used because it doesn't work " + "when the configuration item is repeated. Use <label class=\"attach-previous\"> " + "to have your label attach to the previous DOM node instead."); } }
@Override public String provideContent(String documentToProcess, ResourceToUpdate resourceToUpdate) throws IssueProvidingContentException { Document originalDocument = parseStringIntoDocument(documentToProcess); List<Node> elementUnderXpathWeLookFor = originalDocument.selectNodes(xpathElementToRemove); if (elementUnderXpathWeLookFor.isEmpty()) { log.info(xpathElementToRemove + " didn't match any element - not removing any element"); return documentToProcess; } elementUnderXpathWeLookFor.stream().forEach(e -> e.detach()); return prettyPrint(originalDocument); }
@Override public MonitorConf loadJmxConfig() { MonitorConf monitorConf = new MonitorConf(); Element monitor = (Element) doc.selectNodes("//jobs/monitor").get(0); monitorConf.setJmxRmiHost(monitor.attributeValue("rHost")); monitorConf.setJmxRmiPort(Integer.valueOf(monitor.attributeValue("rPort"))); monitorConf.setJmxHttpHost(monitor.attributeValue("httpHost")); monitorConf.setJmxHttpPort(Integer.valueOf(monitor.attributeValue("httpPort"))); return monitorConf; }
public List<Review> parse(final FishEyeDocumentHolder docHolder) throws IOException { final Document doc = docHolder.getDoc(); final List<Review> reviews = new ArrayList<Review>(); if (doc != null) { final List<Node> reviewNodes = doc.selectNodes("/reviews/reviewData"); reviews.addAll(parse(reviewNodes, docHolder.getBaseUrl(), null)); } return reviews; }
public void testBug857704() throws Exception { Document doc = DocumentHelper .parseText("<foo xmlns:bar='http://blort'/>"); doc.selectNodes("//*[preceding-sibling::*]"); // shouldn't throw NPE }
public void testXPaths() throws Exception { List list = document.selectNodes("//SPEAKER", "NAME"); log("Number of SPEAKER instances: " + list.size()); List noDuplicates = document.selectNodes("//SPEAKER", ".", true); log("Number of distinct SPEAKER instances: " + noDuplicates.size()); log("Number of distinct SPEAKER instances: " + noDuplicates.size()); }
public void testTransform() throws Exception { Document transformedDoc = transform("/xml/nitf/ashtml.xsl"); // log( transformedDoc.asXML() ); assertTrue("Transformed Document is not null", transformedDoc != null); List h1List = transformedDoc.selectNodes("/html//h1"); assertTrue("At least one <h1>", h1List.size() > 0); List pList = transformedDoc.selectNodes("//p"); assertTrue("At least one <p>", pList.size() > 0); }
protected void testXPath(String xpathExpression) { XPath xpath = DocumentHelper.createXPath(xpathExpression); assertTrue("No xpath object was created", xpath != null); log("Evaluating xpath: " + xpath); List list = document.selectNodes("//author"); for (Iterator iter = list.iterator(); iter.hasNext();) { Node node = (Node) iter.next(); testXPath(node, xpath); } }
public void testBug527062() throws Exception { Document doc = getDocument("/xml/test/test.xml"); List<Node> l = doc.selectNodes("//broked/junk"); for (Node aL : l) { System.out.println("Found node: " + ((Element) aL).getStringValue()); } assertEquals("hi there", ((Element) l.get(0)).getStringValue()); assertEquals("hello world", ((Element) l.get(1)).getStringValue()); }
protected void testNamespaceForDefaultPrefix(Document document) throws Exception { List<Node> list = document.selectNodes("//*"); for (Node node : list) { Element element = (Element) node; Namespace ns = element.getNamespaceForPrefix(""); assertNamespace(ns, "", "dummyNamespace"); ns = element.getNamespaceForPrefix(null); assertNamespace(ns, "", "dummyNamespace"); log("found: " + ns.asXML()); } }