xpath expression to remove whitespace

I. Use this single XPath expression: translate(normalize-space(/tr/td/a), ‘ ‘, ”) Explanation: normalize-space() produces a new string from its argument, in which any leading or trailing white-space (space, tab, NL or CR characters) is deleted and any intermediary white-space is replaced by a single space character. translate() takes the result produced by normalize-space() and produces a … Read more

Java: how to locate an element via xpath string on org.w3c.dom.document

Try this: //obtain Document somehow, doesn’t matter how DocumentBuilder b = DocumentBuilderFactory.newInstance().newDocumentBuilder(); org.w3c.dom.Document doc = b.parse(new FileInputStream(“page.html”)); //Evaluate XPath against Document itself XPath xPath = XPathFactory.newInstance().newXPath(); NodeList nodes = (NodeList)xPath.evaluate(“/html/body/p/div[3]/a”, doc, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); ++i) { Element e = (Element) nodes.item(i); } With the following page.html file: <html> <head> … Read more

XPath to get all child nodes (elements, comments, and text) without parent

From the documentation of XPath ( http://www.w3.org/TR/xpath/#location-paths ): child::* selects all element children of the context node child::text() selects all text node children of the context node child::node() selects all the children of the context node, whatever their node type So I guess your answer is: $doc/PRESENTEDIN/X/child::node() And if you want a flatten array of … Read more

Difference between XPath, XQuery and XPointer

Wikipedia is a good place to start for questions like this. Generally, XPath is a language used to succinctly pinpoint exact XML nodes in a DOM. XQuery is a superset of XPath that also provides FLWOR syntax, which is SQL-like. Finally, XPointer includes XPath, but also provides a simpler position-based addressing scheme. Of course, you … Read more

What are good CLI tools for JSON?

I just found this: http://stedolan.github.io/jq/ “jq is a lightweight and flexible command-line JSON processor.” 2014 update: @user456584 mentioned: There’s also the ‘json’ command (e.g. ‘jsontool’). I tend to prefer it over jq. Very UNIX-y. Here’s a link to the project: github.com/trentm/json – in the json README at http://github.com/trentm/json there is a long list of similar … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)