tags:

views:

41

answers:

2

Hi,

I want to mach (in real case I use DomDocument php) a link inside:

Case:

<div class="d1">
  <span class="s1">
    <a class="myclass">my link</a>
  </span>
</div>

My solution that fail:

'//div[@class="d1"]/span[@class="s1"]/a[@class="myclass"]'

what should i change in my xpath expression?

Edit: In real case I have in middle of div before span also other tags. Soo I solve the problem by add / before span :

'//div[@class="d1"]//span[@class="s1"]/a[@class="myclass"]'

Thanks

+1  A: 

Could you try

'//div[./@class="d1"]/span[./@class="s1"]/a[./@class="myclass"]'

Also using the example you have given would

//a[./@class="myclass"]

not suffice?

Hobozilla
+1  A: 

Your XPath seems to be correct. Probably you are trying to query an XHTML document? Then you have to mind the XHTML namepace:

// 1. registerXPathNamespace xhtml with your tool
// 2. query:
'//xhtml:div[@class="d1"]/xhtml:span[@class="s1"]/xhtml:a[@class="myclass"]'

just an idea...

Dennis Knochenwefel