I'm sure this will have an obvious answer and that it's something that
I've just been looking at for too long...
I'm trying to select a node from xml where a child has a specific value
For example:
var xml:XML =
<communication xmlns="stuffHERE">
<folder>
<id>1</id>
<folder>
<id>2</id>
</folder>
<folder>
<id>3</id>
<folder>
<id>4</id>
</folder>
</folder>
</folder>
In the above, I'm using an e4x expression that looks like:
xml..folder.(id == 3)
All works well when I don't have a namespace declared.
When I have a name space declared, I keep getting nothing back.
I'm using the actionscript object: namespace test="http..."
use namespace test
Any ideas on what I'm doing wrong? BTW, I've tried many, many
different e4x expressions, none that work.
Also, any techniques for debugging e4x? I've already included some
dynamic e4x expression parsers that I found on the web. But I find
that while I can get the expression to work fine dynamically, it still
doesn't work.
I've posted this over in teh Adobe Forums, too, as I'm not really sure
which place is the best place to go for help.
Thanks a bunch
Here's my test MXML file, sorry for how ugly it looks in this window.,
I"m hoping you can just copy this and paste it into a new MXML file
for you to look at...:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="horizontal">
<mx:Script>
<![CDATA[
import mx.logging.targets.TraceTarget;
import com.theriabook.util.logging.TraceLogOutput;
private var comm:XML =
<CommunicationHierarchy
xmlns="http://www.directTestmarketing.com/ws/schemas/communicationHierarchyService">
<folder>
<id>13</id>
<recordType>FOLDER</recordType>
<iconId>icon id</iconId>
<label>label</label>
<shortDescription>short description</shortDescription>
<description>Folder 21 description</description>
<externalId>1</externalId>
<template>
<id>21</id>
<recordType>TEMPLATE</recordType>
<iconId>icon id</iconId>
<label>label</label>
<shortDescription>short description</shortDescription>
<description>Template 22 description</description>
<externalId>1</externalId>
</template>
<folder>
<id>14</id>
<recordType>FOLDER</recordType>
<iconId>icon id</iconId>
<label>label</label>
<shortDescription>short description</shortDescription>
<description>Folder 31 description</description>
<externalId>1</externalId>
<link>
<id>13</id>
<recordType>TEMPLATE</recordType>
<iconId>icon id</iconId>
<label>link label</label>
<url>link url</url>
<shortDescription>short description</shortDescription>
<description>description of link - 14</description>
</link>
</folder>
<folder>
<id>15</id>
<recordType>FOLDER</recordType>
<iconId>icon id</iconId>
<label>label</label>
<shortDescription>short description</shortDescription>
<description>Folder 36 description</description>
<externalId>1</externalId>
<link>
<id>15</id>
<recordType>TEMPLATE</recordType>
<iconId>icon id</iconId>
<label>link label</label>
<url>link url</url>
<shortDescription>short description</shortDescription>
<description>description of link - 16</description>
</link>
</folder>
<link>
<id>8</id>
<recordType>TEMPLATE</recordType>
<iconId>icon id</iconId>
<label>link label</label>
<url>link url</url>
<shortDescription>short description</shortDescription>
<description>description of link - 9</description>
</link>
<link>
<id>12</id>
<recordType>TEMPLATE</recordType>
<iconId>icon id</iconId>
<label>link label</label>
<url>link url</url>
<shortDescription>short description</shortDescription>
<description>description of link - 13</description>
</link>
</folder>
<template>
<id>44</id>
<recordType>TEMPLATE</recordType>
<iconId>icon id</iconId>
<label>label</label>
<shortDescription>short description</shortDescription>
<description>Template 45 description</description>
<externalId>1</externalId>
</template>
<template>
<id>45</id>
<recordType>TEMPLATE</recordType>
<iconId>icon id</iconId>
<label>label</label>
<shortDescription>short description</shortDescription>
<description>Template 46 description</description>
<externalId>1</externalId>
</template>
</CommunicationHierarchy>
private namespace directTest =
"http://www.directTestmarketing.com/ws/schemas/communicationHierarchyService";
use namespace directTest;
public var directTest2:Namespace = new
Namespace("http://www.directTestmarketing.com/ws/schemas/communicationHierarchyService");
private function onGoClick(e:MouseEvent):void
{
use namespace directTest;
var xml:XML = new XML(inputXML.text);
// All these filters didn't work:
// new XMLList(xml..folder.(id ==13));
// new XMLList(xml..folder.("id" =="13"));
//
//
//
//
//
// These Worked:
// new XMLList(xml.folder[0])
// new XMLList(xml..folder.(id ==
13));
// new
XMLList(xml.descendants("folder").(id == 13));
//
//var filterdXML:XMLList = new
XMLList(directTest2::folder.(id ==
13));
var filterdXML:XMLList = new
XMLList(xml.descendants("folder").(id
== 13));
outputXML.text = filterdXML.toXMLString();
}
]]>
</mx:Script>
<mx:TraceTarget level="0" />
<mx:TextArea id="inputXML" width="100%" height="100%"
text="{comm.toXMLString()}"/>
<mx:Button id="go" click="onGoClick(event)" />
<mx:TextArea id="outputXML" width="100%" height="100%" />
</mx:Application>