使用 PHP SimpleXml 从 xmlfeed 选择特定 id
我有一个使用 ID 或类型的 XML Feed。我需要选择特定节点并将其转换为变量。
XML Feed 示例:
<tour>
<tourName>Amazon Riverboat Adventure</tourName>
<dossierCode>PVIIA</dossierCode>
<tripDetails>
<tripDetail type="StartFinish">ex Lima</tripDetail>
<tripDetail type="What's Included">Lots of stuff </tripDetail>
</tripDetails>
我一直在使用以下方法提取此数据:
<?php
if(!$xml=simplexml_load_file('xmlfeed.xml')){
trigger_error('Error reading XML file',E_USER_ERROR);
}
foreach ($xml->tourName as $tourname)
foreach ($xml->dossierCode as $agentcode)
?>
但是我不确定如何将
提取为 $startfinish。
有人可以帮忙吗?
非常感谢!
I have an XML Feed which is using ID's or Types. I need to select the specific node and convert it to a variable.
Example XML Feed:
<tour>
<tourName>Amazon Riverboat Adventure</tourName>
<dossierCode>PVIIA</dossierCode>
<tripDetails>
<tripDetail type="StartFinish">ex Lima</tripDetail>
<tripDetail type="What's Included">Lots of stuff </tripDetail>
</tripDetails>
I have been extracting this data by using:
<?php
if(!$xml=simplexml_load_file('xmlfeed.xml')){
trigger_error('Error reading XML file',E_USER_ERROR);
}
foreach ($xml->tourName as $tourname)
foreach ($xml->dossierCode as $agentcode)
?>
However I am unsure how I can extract the <tripDetail type="StartFinish">
as $startfinish.
Can anyone help?
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://www.php.net/manual/en/simplexmlelement.attributes.php
http://www.php.net/manual/en/simplexmlelement.attributes.php