PHPglob
の場合:XMLファイル、xpath
すべてのノード、preg_match_all
それらのテキスト、および一致する場合は、ノードのxpathを取得しgetNodePath()
て出力します。
$pattern = '/home|house|guide/iu';
foreach (glob('data/*.xml') as $file)
{
foreach (simplexml_load_file($file)->xpath('//*') as $node)
{
if (!preg_match_all($pattern, $node, $matches)) continue;
printf(
"\"%s\" in %s, xpath: %s\n", implode('", "', $matches[0]),
basename($file), dom_import_simplexml($node)->getNodePath()
);
}
}
結果(例):
"Guide" in iana-charsets-2013-03-05.xml, xpath: /*/*[7]/*[158]/*[4]
"Guide" in iana-charsets-2013-03-05.xml, xpath: /*/*[7]/*[224]/*[2]
"Guide" in iana-charsets-2013-03-05.xml, xpath: /*/*[7]/*[224]/*[4]
"guide" in rdf-dmoz.xml, xpath: /*/*[4]/d:Description
"guide" in rdf-dmoz.xml, xpath: /*/*[5]/d:Description
いい質問です。