0

ornek.xml here :

<?xml version="1.0" encoding="UTF-8"?>
<library>
    <book onay="e" katid="31" dil="tr">
        <kitapadi>Dear Lovely</kitapadi>
        <yazar>Author 1234</yazar>
        <isbn>1234513</isbn>
         </book>
         <book onay="e" katid="32" dil="en">
        <kitapadi>Love and Hate</kitapadi>
        <yazar>Author 345</yazar>
        <isbn>1234513</isbn>
         </book>
</library>

PHP Code:

$xml = simplexml_load_file('veri/ornek.xml');
$search= '34';
$result = $xml->xpath('//yazar[contains(.,"'.$search.'")]');
foreach($result as $tt){
    echo $tt;
    }

If I use this, I can get the yazar attributes. But I want get another attributes example:

$search = 34 where match yazar 34 giving this block in kitapadi,isbn,yazar

4

2 回答 2

0

如果您想在 yazar 获得包含 serach sring 的书。使用这样的东西:

$xml = simplexml_load_file('veri/ornek.xml');
$search= "34";
$result = $xml->xpath("//book[yazar[contains(.,' $search')]]");
foreach($result as $tt){
    echo $tt->isbn;
    }
于 2013-05-01T19:41:39.400 回答
0

这个 XPath 查询可以解决问题:

//*[text()[contains(., '34')]]

结果:

Element='<yazar>Author 1234</yazar>'
Element='<isbn>1234513</isbn>'
Element='<yazar>Author 345</yazar>'
Element='<isbn>1234513</isbn>'
于 2013-05-01T18:42:43.353 回答