繁体   English   中英

加载xml文档并使用xpath对其进行过滤

[英]Loading xml document and filter it with xpath

我使用PHP加载XML文档:

$xmlDocument = file_get_contents($url, false, $context);
$xmlString = simplexml_load_string($xmlDocument);

XmlString和$ url: http ://testing.zwiink.us/getPurchased.php

现在,我试图过滤掉包含以下内容的每个元素:

[u] => /zwinky/fds/creations/

我尝试使用xpath,但始终失败,我想我使用了错误的搜索值。 有谁知道我将如何工作?

您首先需要使用contains()进行xpath查询:

$xmlDocument = file_get_contents($url, false, $context);
$xmlString = simplexml_load_string($xmlDocument);

// target elements with that attribute
$u = $xmlString->xpath('//*[contains(@u, "/zwinky/fds/creations/")]');

echo '<pre>';
print_r($u);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM