Aşağıda, bir XML dosyasında arama yapıp <AnotherChild>
kimliğini bulmam gereken bir PHP script var. Herhangi bir nedenle, şu anda 0 sonuç döndürüyor ve nedenini anlayamıyorum. Herhangi biri neden 0 döndürdüğünü görebiliyorsa, nedenini bilmeme izin verirse gerçekten çok memnun olurum.PHP XPath arama dönen 0 sonuç
XML:
<TransXChange xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.transxchange.org.uk/" xsi:schemaLocation="http://www.transxchange.org.uk/ http://www.transxchange.org.uk/schema/2.1/TransXChange_general.xsd" CreationDateTime="2013-07-12T18:12:21.8122032+01:00" ModificationDateTime="2013-07-12T18:12:21.8122032+01:00" Modification="new" RevisionNumber="3" FileName="swe_44-611A-1-y10.xml" SchemaVersion="2.1">
<Node1>...</Node1>
<Node2>...</Node2>
<Node3>...</Node3>
<Node4>...</Node4>
<Node5>...</Node5>
<Node6>...</Node6>
<Node7>
<Child>
<id>ABCDEFG123</id>
</Child>
<AnotherChild>
<id>ABCDEFG124</id>
</AnotherChild>
</Node7>
<Node8>...</Node8>
</TransXChange>
PHP:
<?php
$xmldoc = new DOMDocument();
$xmldoc->load("directory1/directory2/file.xml");
$xpathvar = new DOMXPath($xmldoc);
$xpathvar->registerNamespace('transXchange', 'http://www.transxchange.org.uk/');
$queryResult = $xpathvar->query('//AnotherChild/id');
foreach($queryResult as $result) {
echo $result->textContent;
}
?>
Teşekkür
[ad ile xpath] (http olası yinelenen: // stackoverflow.com/questions/9827685/xpath-with-namespace) – Wrikken
[bununla birlikte daha iyi olabilir] (http://stackoverflow.com/questions/6475394/php-xpath-query-on-xml-with-default- ad alanı-bağlayıcı) – Wrikken
@Wrikken Her iki cevaba da baktım ve sorunumu gidermek için kodumu nasıl ayarlayacağımı göremedim? – jskidd3