0
 <multi-routing-engine-item>

        <re-name>n</re-name>

        <zones-information xmlns="http://xml48/juzones" j:s="de">
            <zones-security>
                <zones-security-zonename>A</zones-security-zonename>
                <zones-security-interfaces>
                    <zones-security-interface-name>reth2.66</zones-security-interface-name>
                    <zones-security-interface-name>2.68</zones-security-interface-name>
                </zones-security-interfaces>
            </zones-security>
            <zones-security>        
                <zones-security-zonename>B</zones-security-zonename>

question1:

 >>> response_zone.xpath("//zones-information/zones-security[//zones-security-interface-name[text()='reth2.66']]/zones-security-zonename/text()")
    ['A', 'B', 'C']
    >>> 
    >>> response_zone.xpath("//zones-information/zones-security[.//zones-security-interface-name[text()='reth2.66']]/zones-security-zonename/text()")
    ['A']

what is the difference between .// and // in this context. A little bit confused.

question2:

>>> response_zone.xpath(".//zones-security[.//zones-security-interface-name[text()='reth2.66']]/zones-security-zonename/text()")
['A']
>>> response_zone.xpath("//zones-security[.//zones-security-interface-name[text()='reth2.66']]/zones-security-zonename/text()") 
['A']

in question2 , they have same result.....

I am confused by this . need help.

Robbie
  • 53
  • 1
  • 8
  • `.` refers to the current node. And if a query begins with a `/` or `//` it's relative to the root of the document. `//` goes through all descendants. Put that together and what do you get? – Jeff Mercado Jun 30 '17 at 02:51

1 Answers1

0

Read this for xPath https://en.wikipedia.org/wiki/XPath =)

. - s short for self::node(), reference for current node

// - is short for /descendant-or-self::node()/, search inside all nodes on all layers

.// - search from current node on all layers

./ search from current node 1 layer below

so when you do:

//something[.//another] - something that has another inside on any layer

//something[./another] - something that has another as child

//something[//another] - something , but somewhere in the file another should be too [not just inside something, but anywhere]

//something//another - another that has something as parent on any layer

//something/another - something that direct parentanother

//something.//another - error, as syntax is not correct, use just // instead =)

when you just start locator with // or .// - there's no difference as starting point is root document element, so it will search inside whole file anyway

Vitaliy Moskalyuk
  • 2,463
  • 13
  • 15
  • //something[//another] :if it can find another in somewhere, xpath respond with all the value under //something .like what I get :response_zone.xpath("//zones-information/zones-security[//zones-security-interface-name[text()='reth2.66']]/zones-security-zonename/text()") ['A', 'B', 'C'] .Am I correct? – Robbie Jul 01 '17 at 08:46
  • I want to understand why it responds all zones-secur‌​ity-zonename/text() in case I use //something[//another] – Robbie Jul 01 '17 at 08:49
  • because you are searching not from current node, use `.//` instead=) that's just how xpath works, i'm not sure why they implemented it in this way. But using this you can, for example, get some value that is totally not related to current node (for example some pages amount) and use it in current node. I think that was the main reason. – Vitaliy Moskalyuk Jul 01 '17 at 09:13
  • yes, I know I seach not from current node [//zones-security-interface-name[text()='reth2.66'] ,but the whole path is :response_zone.xpath("//zones-information/zones-security[//zones-security-interface-name[text()='reth2.66']]/zones-security-zonename/text()") . How to understand this? – Robbie Jul 03 '17 at 06:42