1
我会创建一个函数(with,depth ...)来获取xml中的一些元素。 我的循环提取信息时出现问题。如何提取特定的xml信息
谢谢
例如:
echo $IceCatByEan->getSpecByName('width'); // size
echo $IceCatByEan->getSpecByName('depth'); // size
echo $IceCatByEan->getSpecByName('dimension_type'); // mn, cm
ceCatByEan-> getSpecByName( 'DIMENSION_TYPE'); // mn个
功能
// specificationName (like with, depth, dimension_type)
public function getSpecByName($specificationName) {
$xml = $this->getSearchProductEanXML();
$spec_item = $xml->xpath("//ProductFeature");
foreach ($spec_item as $feature) {
...
}
return $element;
}
阵列呈现
[特征] =>数组 ( [44095] =>数组 ( [名称] =>堆叠宽度 [值] => 2453.64 [sign] => mm [pres_value] => 2453.6 mm ) )
XML文件
<ProductFeature Localized="0" ID="241810932" Local_ID="0" Value="2192.02" CategoryFeature_ID="87011" CategoryFeatureGroup_ID="10073" No="100025" Presentation_Value="2192 mm" Translated="0" Mandatory="1" Searchable="0">
<LocalValue Value="2192">
<Measure ID="24">
<Signs><Sign ID="3" langid="1"><![CDATA[mm]]></Sign></Signs>
</Measure>
</LocalValue>
<Feature ID="1649">
<Measure ID="24" Sign="">
<Signs><Sign ID="3" langid="1"><![CDATA[mm]]></Sign></Signs>
</Measure>
<Name ID="5143" langid="1" Value="Width"/>
</Feature>
</ProductFeature>
<ProductFeature Localized="0" ID="241810955" Local_ID="0" Value="71.12" CategoryFeature_ID="87012" CategoryFeatureGroup_ID="10073" No="100024" Presentation_Value="71.1 mm" Translated="0" Mandatory="1" Searchable="0">
<LocalValue Value="71.1">
<Measure ID="24">
<Signs><Sign ID="3" langid="1"><![CDATA[mm]]></Sign></Signs>
</Measure>
</LocalValue>
<Feature ID="1650">
<Measure ID="24" Sign="">
<Signs><Sign ID="3" langid="1"><![CDATA[mm]]></Sign></Signs>
</Measure>
<Name ID="5145" langid="1" Value="Depth"/>
</Feature>
</ProductFeature>
<ProductFeature Localized="0" ID="241810944" Local_ID="0" Value="1249.68" CategoryFeature_ID="87013" CategoryFeatureGroup_ID="10073" No="100023" Presentation_Value="1249.7 mm" Translated="0" Mandatory="1" Searchable="0">
<LocalValue Value="1249.7">
<Measure ID="24">
<Signs><Sign ID="3" langid="1"><![CDATA[mm]]></Sign></Signs>
</Measure>
</LocalValue>
<Feature ID="1464">
<Measure ID="24" Sign="">
<Signs><Sign ID="3" langid="1"><![CDATA[mm]]></Sign></Signs>
</Measure>
<Name ID="4625" langid="1" Value="Height"/>
</Feature>
</ProductFeature>
<ProductFeature Localized="0" ID="241811006" Local_ID="0" Value="2453.64" CategoryFeature_ID="87036" CategoryFeatureGroup_ID="10078" No="99989" Presentation_Value="2453.6 mm" Translated="0" Mandatory="0" Searchable="0">
<LocalValue Value="2453.6">
<Measure ID="24">
<Signs><Sign ID="3" langid="1"><![CDATA[mm]]></Sign></Signs>
</Measure>
</LocalValue>
<Feature ID="3808">
<Measure ID="24" Sign="">
<Signs><Sign ID="3" langid="1"><![CDATA[mm]]></Sign></Signs>
</Measure>
<Name ID="44095" langid="1" Value="Package width"/>
</Feature>
</ProductFeature>
<ProductFeature Localized="0" ID="241811027" Local_ID="0" Value="604.52" CategoryFeature_ID="87037" CategoryFeatureGroup_ID="10078" No="99988" Presentation_Value="604.5 mm" Translated="0" Mandatory="0" Searchable="0">
<LocalValue Value="604.5">
<Measure ID="24">
<Signs><Sign ID="3" langid="1"><![CDATA[mm]]></Sign></Signs>
</Measure>
</LocalValue>
<Feature ID="3806">
<Measure ID="24" Sign="">
<Signs><Sign ID="3" langid="1"><![CDATA[mm]]></Sign></Signs>
</Measure>
<Name ID="44061" langid="1" Value="Package depth"/>
</Feature>
</ProductFeature>
<ProductFeature Localized="0" ID="241811019" Local_ID="0" Value="1480.82" CategoryFeature_ID="87038" CategoryFeatureGroup_ID="10078" No="99987" Presentation_Value="1480.8 mm" Translated="0" Mandatory="0" Searchable="0">
<LocalValue Value="1480.8">
<Measure ID="24">
<Signs><Sign ID="3" langid="1"><![CDATA[mm]]></Sign></Signs>
</Measure>
</LocalValue>
<Feature ID="3807">
<Measure ID="24" Sign="">
<Signs><Sign ID="3" langid="1"><![CDATA[mm]]></Sign></Signs>
</Measure>
<Name ID="44078" langid="1" Value="Package height"/>
</Feature>
</ProductFeature>
这是一个有效的XML文件吗? 预期的结果/输出是什么? – DanielO
这个例子中,xml非常长。 resut很简单,我想提取信息以获得深度的大小,深度的度量。大小将包括在数据库内,也可以测量 – yokogeri