所以我有以下的XML文件,我只對<respcondition>
元素感興趣,其中只有<or>
元素,而不是<and>
元素。Foreach children()SimpleXML不給我完整的結構
我在PHP中嘗試了以下聲明:
<!-- language: lang-php -->
foreach ($item->resprocessing->children() as $child) {
if ((string) $child->getName() == 'respcondition') {
if ((string) $child->respcondition->children()->getName() == 'conditionvar') {
if ((string) $child->respcondition->conditionvar->children()->getName() == 'or') {
$responseID = $child->respcondition->conditionvar->or->varequal->attributes()->respident;
//some code
}
}
}
}
}
但我只來在第一IF,所以我想通了,children()
不包含該元素的整個XML。有一些替代品可以使用嗎?
<!-- language: lang-xml -->
<resprocessing>
<outcomes>
<decvar varname="SCORE" vartype="Decimal" defaultval="0" minvalue="0.0" maxvalue="1.0" cutvalue="1.0"/>
</outcomes>
<respcondition continue="Yes" title="Mastery">
<conditionvar>
<or>
<varequal respident="1000006631" case="Yes"><![CDATA[Mars]]></varequal>
</or>
</conditionvar>
<setvar varname="SCORE" action="Add">1.0</setvar>
</respcondition>
<respcondition continue="Yes" title="Mastery">
<conditionvar>
<or>
<varequal respident="1000006678" case="Yes"><![CDATA[Jupiter]]></varequal>
</or>
</conditionvar>
<setvar varname="SCORE" action="Add">1.0</setvar>
</respcondition>
<respcondition title="Mastery" continue="Yes">
<conditionvar>
<and>
<or>
<varequal respident="1000006421" case="Yes"><![CDATA[planets]]></varequal>
</or>
<or>
<varequal respident="1000006468" case="Yes"><![CDATA[sun]]></varequal>
</or>
<or>
<varequal respident="1000006558" case="Yes"><![CDATA[Mercury]]></varequal>
</or>
</and>
</conditionvar>
<displayfeedback feedbacktype="Response" linkrefid="Mastery"/>
</respcondition>
</resprocessing>
親切的問候