- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下 XML:
<ns1:getBannerLinksResponse xmlns:ns1="http://endpoint.website.com/">
<ns1:return>
<ns1:campaignID>0</ns1:campaignID>
<ns1:categoryID>200230455</ns1:categoryID>
<ns1:categoryName>Promotion</ns1:categoryName>
<ns1:linkID>10001599</ns1:linkID>
<ns1:linkName>KFL-20% off No Min</ns1:linkName>
<ns1:mid>3071</ns1:mid>
<ns1:nid>1</ns1:nid>
<ns1:clickURL>
http://someurl
</ns1:clickURL>
<ns1:endDate>Oct 15, 2012</ns1:endDate>
<ns1:height>250</ns1:height>
<ns1:iconURL>
http://someurl
</ns1:iconURL>
<ns1:imgURL>
http://someurl
</ns1:imgURL>
<ns1:landURL>
http://someurl
</ns1:landURL>
<ns1:serverType>22</ns1:serverType>
<ns1:showURL>
http://someurl
</ns1:showURL>
<ns1:size>13</ns1:size>
<ns1:startDate>Oct 14, 2012</ns1:startDate>
<ns1:width>300</ns1:width>
</ns1:return>
</ns1:getBannerLinksResponse>
我尝试了以下但没有成功:
$data = new SimpleXMLElement($xml);
$data->registerXPathNamespace('ns1','http://endpoint.website.com/');
foreach($data->xpath('//ns1:return') as $banner)
{
$banner->registerXPathNamespace('ns1','http://endpoint.website.com/');
var_dump($banner);
}
最佳答案
你只需要
$data = new SimpleXMLElement($xml);
$data->registerXPathNamespace('ns1','http://endpoint.websitecom/');
$part = $data->xpath("//ns1:return");
var_dump($part[0]->children("ns1",true));
输出
object(SimpleXMLElement)[3]
public 'campaignID' => string '0' (length=1)
public 'categoryID' => string '200230455' (length=9)
public 'categoryName' => string 'Promotion' (length=9)
public 'linkID' => string '10001599' (length=8)
public 'linkName' => string 'KFL-20% off No Min' (length=18)
public 'mid' => string '3071' (length=4)
public 'nid' => string '1' (length=1)
public 'clickURL' => string '
http://someurl
' (length=36)
public 'endDate' => string 'Oct 15, 2012' (length=12)
public 'height' => string '250' (length=3)
public 'iconURL' => string '
http://someurl
' (length=36)
public 'imgURL' => string '
http://someurl
' (length=36)
public 'landURL' => string '
http://someurl
' (length=36)
public 'serverType' => string '22' (length=2)
public 'showURL' => string '
http://someurl
' (length=36)
public 'size' => string '13' (length=2)
public 'startDate' => string 'Oct 14, 2012' (length=12)
public 'width' => string '300' (length=3)
关于php - SimpleXMLElement 使用命名空间访问元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12865858/
SimpleXMLElement 的“addChild”方法似乎应该是正确的选择,但它显然只接受表示新 child 的标记名的字符串。 有用于引用树节点并设置它们的对象式表示法,例如$simpleXM
我有以下 XML: 0 200230455 Promotion 10001599 KFL-20% off N
我正在编写一个 PHP 脚本来生成一些 xml 文档,但我在使用 SimpleXML 和引号时遇到了一些问题。 如果我有这样的代码: $xml = new SimpleXMLElement('');
我有以下 XML: 0 200230455 Promotion 10001599 KFL-20% off N
我正在编写一个 PHP 脚本来生成一些 xml 文档,但我在使用 SimpleXML 和引号时遇到了一些问题。 如果我有这样的代码: $xml = new SimpleXMLElement('');
我做了一个这样的函数: function getFeed($feed_url) { $content = file_get_contents($feed_url); $x = new
每个人都知道我们应该始终使用 DOM 技术而不是正则表达式来从 HTML 中提取内容,但我觉得我永远不能相信 SimpleXML 扩展或类似的扩展。 我现在正在编写一个 OpenID 实现,我尝试使用
我正在尝试在我的 php7 laravel 项目中使用 digital ocean 空间。代码非常简单,只需加载一个文件并将其复制到目录即可。一切都在我的本地机器上工作,但在我的 digital oc
我到处搜索这个,我遇到了很多问题,但我不认为这是实际代码的问题。基本上这段代码在两个单独的线程中启动套接字服务器(登录和游戏),我基本上是从非线程版本转换这段代码,但我一直无法让它为线程工作。 inc
我找到了 ( here) 一个关于删除 SimpleXMLElement 对象节点的方法的答案。 问题是我无法真正理解这是怎么发生的。 我的意思是,$image var 是一个 ref,对吧?那么,$
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
我正在尝试在 Wordpress 中创建一个 Widget,但在创建 SimpleXMLElement 对象时遇到了问题。 代码如下: namespace GenieKnows_Search; cl
我正在尝试访问以下元素中的数字,但无法从中获取值。 echo $object->0; //returns Parse error: syntax error, unexpected T_LNUMBER
我在加载外部 XML 文件时遇到问题。 当我在浏览器中打开它时,一切看起来都很好。我尝试下载 XML 文件并将其上传到我自己的服务器上。当我尝试从我的服务器加载 XML 文件时,一切正常。 有人可以帮
我是第一次使用 SimpleXMLElement,需要在我的 XML 中生成一行,如下所示: 我之前没有对命名空间使用过 addAttribute 并且无法在这里使用正确的语法 - 我已经开始了:
我正在解析一个 Webserivce 响应并且我有一个奇怪的行为, 这是what returns me the WS的一个小例子 输出是用 var_dump($results); 完成的 但如果我这样
我正在查询YouTrack的网络服务以获取问题列表。响应是如下所示的XML: Bug
我正在使用 xpath 解析网页中的文本,但它将它作为对象返回,我如何将其作为字符串返回。 libxml_use_internal_errors(TRUE); $dom = new DOMDocume
如何访问作为数组的 SimpleXMLElement 子项? SimpleXMLElement(9) { name => "John" (11) phone => array(2) [ 0
我有这个: [1]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(14) { ["name"]=>
我是一名优秀的程序员,十分优秀!