Flex e4x - выбор по нескольким атрибутам
<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)
По сути, запрос по обоим атрибутам [имя и значение] для данного имени проекта
2 ответа
Решение
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>
@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>