XPath – Get node with no child of specific type

Maybe *[local-name() = ‘A’ and not(descendant::*[local-name() = ‘B’])]? Also, there should be only one root element, so for /A[…] you’re either getting all your XML back or none. Maybe //A[not(B)] or /*/A[not(B)]? I don’t really understand why /A[not(B)] doesn’t work for you. ~/xml% xmllint ab.xml <?xml version=”1.0″?> <root> <A id=”1″> <B/> </A> <A id=”2″> </A> … Read more

Using XPath, How do I select a node based on its text content and value of an attribute?

Generally I would consider the use of an unprefixed // as a bad smell in an XPath. Try this:- /DocText/WithQuads/Page/Word[text()=’July’ and Quad/P1/@X > 90] Your problem is that you use the //P1[@X < 90] which starts back at the beginning of the document and starts hunting any P1 hence it will always be true. Similarly … Read more

Javascript get XPath of a node

I refactored this from another example. It will attempt to check or there is for sure a unique id and if so use that case to shorten the expression. function createXPathFromElement(elm) { var allNodes = document.getElementsByTagName(‘*’); for (var segs = []; elm && elm.nodeType == 1; elm = elm.parentNode) { if (elm.hasAttribute(‘id’)) { var uniqueIdCount … Read more

XPath to return only elements containing the text, and not its parents

Do you want to find elements that contain “match”, or that equal “match”? This will find elements that have text nodes that equal ‘match’ (matches none of the elements because of leading and trailing whitespace in random2): //*[text()=’match’] This will find all elements that have text nodes that equal “match”, after removing leading and trailing … Read more

How to use regex in XPath “contains” function

XPath 1.0 doesn’t handle regex natively, you could try something like //*[starts-with(@id, ‘sometext’) and ends-with(@id, ‘_text’)] (as pointed out by paul t, //*[boolean(number(substring-before(substring-after(@id, “sometext”), “_text”)))] could be used to perform the same check your original regex does, if you need to check for middle digits as well) In XPath 2.0, try //*[matches(@id, ‘sometext\d+_text’)]

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