<EFM>
<projects>
<project name="EFM Columbus Supply Chain Project">
<characteristics>
<characteristic name="Types of Data">
<textDescription></textDescription>
<options>
<option name="Commodity Flow" value="True"/>
<option name="Industry Assets" value="False"/>
<option name="Trade Data" value="True"/>
<option name="Infrastructure" value="False"/>
<option name="Economic Data" value="False"/>
<option name="Benefits Information" value="True"/>
<option name="Supply Chain Event Data" value="False"/>
<option name="Physical Movement Data" value="False"/>
<option name="Other" value="True"/>
</options>
</characteristic>
</characteristics>
</project>
</projects>
</EFM>
我想按此标准选择节点的XMLList
<Projects>.<project>.@name = x && <Projects>.<project>.<characteristics>.<characteristic>.<options>.<option>.(@name == y && @value == z)
基本上按给定项目名称
的属性[名称和值]进行查询答案 0 :(得分:3)
trace(xml.projects.project.(@name == "EFM Columbus Supply Chain Project").characteristics.characteristic.options.option.(@name == "Other" && @value == "True").toXMLString());
//traces <option name="Other" value="True"/>
//broken down to fit in the screen:
trace(
xml.projects.project.(
@name == "EFM Columbus Supply Chain Project"
).characteristics.characteristic.options.option.(
@name == "Other" && @value == "True"
).toXMLString()
);
更新:以防万一你想获得项目标签而不是选项标签:
var xml:XML =
<EFM>
<projects>
<project name="EFM 1" id="wrong">
<characteristics>
<characteristic name="Types of Data">
<options>
<option name="Benefits Information" value="True"/>
<option name="Supply Chain Event Data" value="False"/>
<option name="Physical Movement Data" value="False"/>
<option name="Other" value="True"/>
</options>
</characteristic>
</characteristics>
</project>
<project name="EFM 1" id="right">
<characteristics>
<characteristic name="Types of Data">
<options>
<option name="Benefits Information" value="True"/>
<option name="Supply Chain Event Data" value="False"/>
<option name="Physical Movement Data" value="False"/>
<option name="Other" value="False"/>
</options>
</characteristic>
</characteristics>
</project>
<project name="EFM 2" id="wrong">
<characteristics>
<characteristic name="Types of Data">
<options>
<option name="Benefits Information" value="True"/>
<option name="Supply Chain Event Data" value="False"/>
<option name="Physical Movement Data" value="False"/>
<option name="Other" value="False"/>
</options>
</characteristic>
</characteristics>
</project>
</projects>
</EFM>;
E4X:
trace(xml.projects.project.(@name == "EFM 1" && characteristics.characteristic.options.option.(@name == "Other").@value == "False").toXMLString());
//broken down to fit in the screen
trace(
xml.projects.project.(
@name == "EFM 1" && characteristics.characteristic.options.option.(
@name == "Other"
).@value == "False"
).toXMLString()
);
输出:
<project name="EFM 1" id="right">
<characteristics>
<characteristic name="Types of Data">
<options>
<option name="Benefits Information" value="True"/>
<option name="Supply Chain Event Data" value="False"/>
<option name="Physical Movement Data" value="False"/>
<option name="Other" value="False"/>
</options>
</characteristic>
</characteristics>
</project>
答案 1 :(得分:0)
@Amarghosh在<option>
节点之间<characteristic>
节点列表相同的情况下,您的查询不会返回预期的项目
我正在尝试选择项目
<characteristics>.<characteristic>.(@name == "Frequency of Data Sharing")
&& <characteristics>.<characteristic>.<options>.<option>.(@Near Real Time == "True")
using the query
projectsXML.projects.project.(
characteristics.characteristic.(@name == prjCharacteristicsFilter)
&& characteristics.characteristic.options.option.(@name == s).@value == "True") ;
这是XML:
<EFM>
<projects>
<project id="2" name="EFM Columbus Supply Chain Project">
<characteristics>
<characteristic name="Frequency of Data Sharing" projectPropertyName="sharingFreqArrayColl">
<textDescription></textDescription>
<options>
<option name="Near Real Time" value="True"/>
<option name="Hourly" value="False"/>
<option name="Daily" value="False"/>
<option name="Periodically" value="False"/>
<option name="One Time" value="False"/>
</options>
</characteristic>
<characteristic name="Frequency of Update of Data" projectPropertyName="updateFreqArrayColl">
<textDescription></textDescription>
<options>
<option name="Near Real Time" value="False"/>
<option name="Hourly" value="True"/>
<option name="Daily" value="False"/>
<option name="Periodically" value="False"/>
<option name="One Time" value="False"/>
</options>
</characteristic>
</characteristics>
</project>
</projects>
</EFM>