我在PHP中成功解析了xml文件,但难以解析试图输出表的特定条目。解析XML数据的PHP
我的XML是作为遵循
<OutputData Name="ExchangeRate" ContentTypeID="">
<DataTitle>Exchange</DataTitle>
<DataInfo>
<TABLE CLASS="DataTable">
<TR><TD>1.00 GBP = 1.68 ALL</TD></TR>
<TR><TD>1.00 USD = 1.58 ALL</TD></TR>
<TR><TD>1.00 EUR = 1.35 ALL</TD></TR>
<TR><TD>Currency conversion rates as of January 2012</TD></TR>
</TABLE>
</DataInfo>
</OutputData>
,如果我尝试这样 我得到一个错误输出。
有帮助吗?
我的代码遵循
$xmlfile = $currenttitle.".xml";
$info = simplexml_load_file($xmlfile);
$region = $country->Region[0];
$section = $region->Section;
if($info){
foreach ($region->Section as $sectioninfo){
$title = $sectioninfo->SectionTitle;
echo "<b>$title</b><br />\n";
$output = $sectioninfo->OutputData;
foreach ($sectioninfo->OutputData as $outputinfo){
$titleinfo = $outputinfo->DataTitle;
$info = $outputinfo->DataInfo;
}
}
的部分上面,我得到的标题显示,作为交换,但表不会被渲染。
SOLUTION 感谢h4b0谁把我在正确的方向
$rowinfo = $outputinfo->DataInfo->TABLE->TR->TD;
foreach ($outputinfo->DataInfo->TABLE->TR as $rowexchange){
echo $rowexchange->TD."<br />";
}
你得到'$ outputinfo'的代码是什么? – Neal 2012-02-08 15:33:07
你如何解析它?什么是'$ outputinfo'?你遇到了什么错误? – 2012-02-08 15:34:04
没有看到您的代码,我们只能猜测... $ info = $ outputinfo ['DataInfo']; – IOInterrupt 2012-02-08 15:34:47