0

我正在尝试创建一个图片库:

<card>
 <product catalog="Thread Works">
    <name>AK E001</name>    
    <price>45</price>
    <path>assets\cards\AK_E001.jpg</path>
 </product>

 <product catalog="Paper Work">
     <name>AK E001</name>   
    <price>45</price>
    <path>assets\cards\AK_PP003.jpg</path>
 </product>

<product catalog="Thread Works">
    <name>AK E002</name>    
    <price>50</price>
    <path>assets\cards\AK_E002.jpg</path>
 </product>

我可以访问该属性,但如果我选择“Thread Works”,我只想访问 <product catalog="Thread Works"> 子节点,以便将项目添加到数组集合中任何帮助谢谢

4

3 回答 3

3

请参阅http://livedocs.adobe.com/flex/3/html/help.html?content=13_Working_with_XML_08.html

在你的情况下:

变量 x:XML; //用你的数据填充Xml

var threadWorks:XML = x.product.(@catalog=="Thread Works");

编辑:警告:不要忘记 . 在产品和@catalog 之间

于 2011-09-08T07:24:45.343 回答
0
function onXmlLoaded (e:Event):void 
{
    xml = XML(e.target.data);
    var xmlLength:Number  = xml.product.length();
    for(var i:uint = 0; i<xmlLength; i++)
    {
            dataContainer.push( {
            catalog : xml.product.@catalog,
            name :  xml..name,
            price : xml..price,
            path : xml..path
        });
    }
    for(i=0;i<dataContainer.length;i++)
    {
           if(dataContainer[i].catalog[0]== "your String"){
                 showName();
           }
    }
}
于 2011-09-08T06:31:12.627 回答
0
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.events.FlexEvent;
            private var mainXML:XML = <card>
                                         <product catalog="Thread Works">
                                            <name>AK E001</name>    
                                            <price>45</price>
                                            <path>assets\cards\AK_E001.jpg</path>
                                         </product>

                                         <product catalog="Paper Work">
                                             <name>AK E001</name>   
                                            <price>45</price>
                                            <path>assets\cards\AK_PP003.jpg</path>
                                         </product>

                                        <product catalog="Thread Works">
                                            <name>AK E002</name>    
                                            <price>50</price>
                                            <path>assets\cards\AK_E002.jpg</path>
                                         </product>
                                        </card>;

            protected function fetchHandler(event:MouseEvent):void
            {
                var productAC:ArrayCollection = new ArrayCollection();
                var productList:XMLList = mainXML.product.(@catalog == attributeNameTxt.text);
                for each(var item:XML in productList)
                {
                    productAC.addItem({name:String(item.name[0]),
                        price:String(item.price[0]),
                        path:String(item.path[0])});
                }
                trace(productAC);
            }

        ]]>
    </fx:Script>
    <s:layout>
        <s:HorizontalLayout/>
    </s:layout>
    <s:TextInput id="attributeNameTxt" text="Thread Works"/>
    <s:Button click="fetchHandler(event);"/>
</s:WindowedApplication>

IMPORTANT CODE : 
=================
mainXML.product.(@catalog == "Thread Works")
于 2011-09-08T07:50:43.323 回答