views:

370

answers:

2
<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>

I want to select a XMLList of nodes by this criteria

<Projects>.<project>.@name = x    &&  <Projects>.<project>.<characteristics>.<characteristic>.<options>.<option>.(@name == y && @value == z)

Essentially query by both attributes [name and value] for a given project name

+2  A: 
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()
);

UPDATE: Just in case you want to get the project tag instead of the option tag:

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>;

The 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()
);

The output:

<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
@Amarghosh Your query fails in a special case. Please see below.
captonssj
A: 

@Amarghosh Your query doesn't return the expected project on this case where the list of <option> nodes are same between <characteristic> nodes

I am trying to select the project where

<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") ;

Here is the 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>
captonssj
What are the values of `prjCharacteristicsFilter` and `s`?
Amarghosh
"Frequency of Data Sharing"
captonssj