这似乎很容易,但我无法理解它: 我有以下传入的xml
<FEEDBACKLIST>
<SUMMARY>
<MODE>product</MODE>
<VENDORLOGON>www.shoponline.co.uk</VENDORLOGON>
<VENDORREF>498</VENDORREF>
<TOTALSERVICECOUNT>1</TOTALSERVICECOUNT>
<TOTALPRODUCTCOUNT>1</TOTALPRODUCTCOUNT>
<COUNT>1</COUNT>
<SUPPLIERLOGO>
http://www.feefo.com/feefo/getnonpublicfile.jsp?vendorimage=777327&vendorimageext=file.png
</SUPPLIERLOGO>
<TITLE>Kawai ES100 Piano</TITLE>
<BEST>100</BEST>
<WORST>0</WORST>
<AVERAGE>100</AVERAGE>
<START>1</START>
<LIMIT>20</LIMIT>
<SERVICEEXCELLENT>1</SERVICEEXCELLENT>
<SERVICEGOOD>0</SERVICEGOOD>
<SERVICEPOOR>0</SERVICEPOOR>
<SERVICEBAD>0</SERVICEBAD>
<PRODUCTEXCELLENT>1</PRODUCTEXCELLENT>
<PRODUCTGOOD>0</PRODUCTGOOD>
<PRODUCTPOOR>0</PRODUCTPOOR>
<PRODUCTBAD>0</PRODUCTBAD>
<TOTALRESPONSES>18</TOTALRESPONSES>
<FEEDGENERATION>Wed Mar 12 16:05:57 GMT 2014</FEEDGENERATION>
<PRODUCTLINK>
http://shop.co.uk/product.php?id=498-Kawai-ES100-Digital-Piano-in-Black
</PRODUCTLINK>
</SUMMARY>
<FEEDBACK>
<FEEDBACKID>117</FEEDBACKID>
<COUNT>1</COUNT>
<DATE>05-Mar-2014</DATE>
<HREVIEWDATE>2014-03-05T20:07:39</HREVIEWDATE>
<DESCRIPTION>Kawai ES100 Piano</DESCRIPTION>
<PRODUCTCODE>498</PRODUCTCODE>
<LINK>
http://shop.co.uk/product.php?id=498-Kawai-ES100-Digital-Piano-in-Black
</LINK>
<FACEBOOKSHARELINK>
http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.feefo.com%2FGB%2Fen%2Freviews%2Fbla%2F%3Fid%3D777327%26servicefeedbackid%3D117
</FACEBOOKSHARELINK>
<HREVIEWRATING>5</HREVIEWRATING>
<PRODUCTRATING>++</PRODUCTRATING>
<CUSTOMERCOMMENT>Great digital piano</CUSTOMERCOMMENT>
<SHORTCUSTOMERCOMMENT>Great digital piano</SHORTCUSTOMERCOMMENT>
<READMOREURL>
http://www.feefo.com/GB/en/reviews/Keysound/?id=777327&productfeedbackid=117
</READMOREURL>
</FEEDBACK>
</FEEDBACKLIST>
我一直在尝试将SUMMARRY COUNT转换为字符串,然后使用它来查看它是否为0,如果不执行其他操作则执行某些操作:
请看一下我的代码:
$xml = simplexml_load_string($xml_filename);
$count= array((string) $xml->FEEDBACKLIST->SUMMARY->COUNT);
if ($count == "0"){
$doc = new DOMDocument();
$xsl = new XSLTProcessor();
$doc->load($curdir."/feedback.xsl");
$xsl->importStyleSheet($doc);
$doc->load($xml_filename2);
echo $xsl->transformToXML($doc);
}
else{
$doc = new DOMDocument();
$xsl = new XSLTProcessor();
$doc->load($curdir."/feedback.xsl");
$xsl->importStyleSheet($doc);
$doc->load($xml_filename);
echo $xsl->transformToXML($doc);
}
任何人都可以建议如何做到这一点吗?
答案 0 :(得分:0)
如果您将$count
定义为array
,则必须在if
声明中检查此数组:
if ($count[0] == "0") { // see the index: [0]
作为替代方案,不要将$count
定义为array
并保留if
- 语句原样:
$count = (string)$xml->SUMMARY->COUNT;
注意:您的XML的根<FEEDBACKLIST>
在$xml
中表示,因此请勿重复。
这是一个有效的演示:https://eval.in/119164