views:

110

answers:

3

I need to get some part of html pages using php XPath query (sorry im new to XPath).

example html page

<html><head>blah lines</head><body>

<div id="mytable">
<table><tr><td>table cell value</td></tr></table>
</div>

<body><html>

is there any way to get div contents of above example along with html tags using XPath

+1  A: 

The following xpath query will return the "mytable" div:

//div[@id='mytable']

//div will select all divs in the document [@id='mytable'] will return only matches with a "mytable" attribute

Scharrels
A: 
/html/body/div[@id='mytable']
knittl
A: 

thank you all, but i was need whole part including tags, so i solved as follows

$detail= $xpath->query("//div [@id='mytable']");
$querycontent = $detail->item(0);
$html->saveXML($querycontent);