views:

516

answers:

2

I'm trying to execute an E4X query (on the xml below) that will return all "accessor" nodes that contain a "metadata" node with a "name" attribute that equals "Required".

I tried...

type.accessor.(metadata.@name == "Required")

...but that only works for accessor nodes that have only 1 metadata node.

Any clues?

<type name="org.springextensions.actionscript.ioc.testclasses::PersonRequiredName" base="org.springextensions.actionscript.ioc.testclasses::Person" isDynamic="false" isFinal="false" isStatic="false">
  <metadata name="__go_to_definition_help">
    <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\PersonRequiredName.as"/>
    <arg key="pos" value="935"/>
  </metadata>
  <extendsClass type="org.springextensions.actionscript.ioc.testclasses::Person"/>
  <extendsClass type="Object"/>
  <constructor>
    <parameter index="1" type="String" optional="true"/>
    <parameter index="2" type="int" optional="true"/>
    <parameter index="3" type="Boolean" optional="true"/>
  </constructor>
  <accessor name="name" access="readwrite" type="String" declaredBy="org.springextensions.actionscript.ioc.testclasses::PersonRequiredName">
    <metadata name="Required"/>
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\PersonRequiredName.as"/>
      <arg key="pos" value="1163"/>
    </metadata>
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\PersonRequiredName.as"/>
      <arg key="pos" value="1249"/>
    </metadata>
  </accessor>
  <variable name="age" type="int">
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="1070"/>
    </metadata>
  </variable>
  <accessor name="siblings" access="readonly" type="Array" declaredBy="org.springextensions.actionscript.ioc.testclasses::Person">
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="3724"/>
    </metadata>
  </accessor>
  <method name="addFriend" declaredBy="org.springextensions.actionscript.ioc.testclasses::Person" returnType="void">
    <parameter index="1" type="org.springextensions.actionscript.ioc.testclasses::Person" optional="false"/>
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="2424"/>
    </metadata>
  </method>
  <method name="toString" declaredBy="org.springextensions.actionscript.ioc.testclasses::Person" returnType="String">
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="3181"/>
    </metadata>
  </method>
  <method name="helloWorld" declaredBy="org.springextensions.actionscript.ioc.testclasses::Person" returnType="String">
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="2159"/>
    </metadata>
  </method>
  <method name="equals" declaredBy="org.springextensions.actionscript.ioc.testclasses::Person" returnType="Boolean">
    <parameter index="1" type="org.springextensions.actionscript.ioc.testclasses::Person" optional="false"/>
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="1932"/>
    </metadata>
  </method>
  <method name="hasSibling" declaredBy="org.springextensions.actionscript.ioc.testclasses::Person" returnType="Boolean">
    <parameter index="1" type="org.springextensions.actionscript.ioc.testclasses::Person" optional="false"/>
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="2789"/>
    </metadata>
  </method>
  <accessor name="writeObject" access="writeonly" type="Object" declaredBy="org.springextensions.actionscript.ioc.testclasses::Person">
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="3950"/>
    </metadata>
  </accessor>
  <variable name="colleague" type="org.springextensions.actionscript.ioc.testclasses::Person">
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="1132"/>
    </metadata>
  </variable>
  <variable name="anArray" type="Array">
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="1166"/>
    </metadata>
  </variable>
  <method name="addSibling" declaredBy="org.springextensions.actionscript.ioc.testclasses::Person" returnType="void">
    <parameter index="1" type="org.springextensions.actionscript.ioc.testclasses::Person" optional="false"/>
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="2605"/>
    </metadata>
  </method>
  <variable name="anObject" type="Object">
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="1197"/>
    </metadata>
  </variable>
  <accessor name="friends" access="readwrite" type="Array" declaredBy="org.springextensions.actionscript.ioc.testclasses::Person">
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="3583"/>
    </metadata>
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="3645"/>
    </metadata>
  </accessor>
  <accessor name="isMarried" access="readwrite" type="Boolean" declaredBy="org.springextensions.actionscript.ioc.testclasses::Person">
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="3434"/>
    </metadata>
    <metadata name="__go_to_definition_help">
      <arg key="file" value="C:\workspace\spring-actionscript\core\src\test\actionscript\org\springextensions\actionscript\ioc\testclasses\Person.as"/>
      <arg key="pos" value="3502"/>
    </metadata>
  </accessor>
</type>
+1  A: 

This seems to work:

type.accessor.(hasOwnProperty("metadata") && metadata.attribute("name").contains("Required"))
Christophe Herreman
A: 

It's all about the parenthesis.

Try this instead (cleaner)

var list:XMLList;

xmlList = type.accessor.metadata.(@name == "Required");
verveguy
That will return all metadata nodes. What I need is all accessor nodes that have a metadata node with a name attribute set to "Required".
Christophe Herreman