I want to perform an if check on an XML file I have loaded in using simplexml_load_file
.
我想使用simplexml_load_file对我加载的XML文件执行if检查。
I have accessed the data when the output is as I want it to be, although as it's web services sometimes they may be a response which I need to cater for. The below is the XML I want to be able to check on:
当输出是我想要的时候,我已经访问了数据,虽然因为它的Web服务有时它们可能是我需要满足的响应。以下是我希望能够检查的XML:
<?xml version="1.0" encoding="utf-8"?>
<ProductSizes />
Can somebody help me out? I am using the below:
有人可以帮帮我吗?我使用以下:
$xmlstock = simplexml_load_file($xmlfeed);
1 个解决方案
#1
1
Assuming that the xml source looks something like the following when actually populated:
假设xml源在实际填充时看起来类似于以下内容:
<?xml version="1.0" encoding="utf-8"?>
<ProductSizes>
<ProductSize />
<ProductSize />
<ProductSize />
</ProductSizes>
You can get a count using the count() api call:
您可以使用count()api调用获取计数:
$xmlstock = simplexml_load_file($xmlfeed);
$hasProductSizes = ($xmlstock->ProductSize->count() > 0) ? true : false;
More info on the count() API via PHP docs.
有关通过PHP文档的count()API的更多信息。
#1
1
Assuming that the xml source looks something like the following when actually populated:
假设xml源在实际填充时看起来类似于以下内容:
<?xml version="1.0" encoding="utf-8"?>
<ProductSizes>
<ProductSize />
<ProductSize />
<ProductSize />
</ProductSizes>
You can get a count using the count() api call:
您可以使用count()api调用获取计数:
$xmlstock = simplexml_load_file($xmlfeed);
$hasProductSizes = ($xmlstock->ProductSize->count() > 0) ? true : false;
More info on the count() API via PHP docs.
有关通过PHP文档的count()API的更多信息。