header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
max
Points:200
Posts:1

3/3/2010 6:23:27 PM

Title: XMLListCollection Search


I need to change this search so it will search the whole Collection
not just one index.

private function updateList():void{
			
			myPCinvCol = new XMLListCollection(myXml..pcinfo.(dept.toLowerCase().indexOf(search_txt.text.toLowerCase()) != -1 ));
											}



1
dGuru
Points: 0
Posts:0
3/3/2010 8:13:44 PM



you can search and access the attribute of xml using something like

var myXmlFile:XML = <myRoot><myNode><firstNode id="node1" value="value1"></firstNode><firstNode id="node2" value="value2"></firstNode></myNode></myRoot>;

myXmlFile.myNode.firstNode.(@id=='node2').@value




2
Dave
Points: 970
Posts:1
3/3/2010 9:16:06 PM



if you want to search use ECMAScript for XML ( E4X ) functionality.

var data:XML =  
     <items>  
         <item name="Fruit">  
             <product>Apple</product>  
             <price>100</price>  
         </item>
 </items>;  

you have two options to make search 

do looping of each node and find the item

or apply filter like this :

you can filter items of the collection
   var items:XMLList = data.item.(product== "Apple" && price < 200);  

you can use unique comparison for getting single item rather than a list.

3
max
Points: 0
Posts:0
3/5/2010 5:34:50 PM



Thank you both for the reply!! I understand what you are saying but I guess I just need to read and learn more about this.

myPCinvCol = new XMLListCollection(myXml..pcinfo.(dept.toLowerCase().indexOf(search_txt.text.toLowerCase()) != -1 )); 

I guess I need to understand what is happening in the above line. I get most of it but don't understand the placement of all the " ( " and also what the -1 would be. So there is now way to use the above syntax but search all of the pcinfo nodes at once? Thanks again for any help.

4
MaxFlash
Points: 0
Posts:0
3/6/2010 12:50:51 AM



HI max , let me explain you the functionality of your code


myPCinvCol = new XMLListCollection(myXml.pcinfo.dept.toLowerCase().indexOf(search_txt.text.toLowerCase()) != -1 )); 



this code will try to search the text provided in textbox (search_txt.text) where dept is not null -1 means that dept is not empty. so the code will search "dept" in your xml's each node for the text you entered. comparison with -1 ensures that if dept value is not present in any node then exception does not occur. if you still have problem in your code then post your xml or upload your project somewhere and post the link here. I will try to fix it up :)

5
Venkatesan
Points: 0
Posts:0
3/31/2010 1:09:28 AM



Hi dave..

I have a little doubt in parsing xml to form objects and give as dataprovider to the DATAGRID..
i knw a way which finds the tag or attribute and convert into objects and assign the same to DATAGRID..
for ex:
if the datagrid has 3 columns, and the code is like this...





<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
	<mx:DataGrid x="90" y="105" id="dg">
		<mx:columns>
			<mx:DataGridColumn headerText="Column 1" dataField="name"/>
			<mx:DataGridColumn headerText="Column 2" dataField="ssn"/>
		</mx:columns>
	</mx:DataGrid>
	
	<mx:Script>
		<![CDATA[
			
			var employees:XML =
                <employees>
                    <employee ssn="123-123-1234">
                        <name first="John" last="Doe"/>
                        <address>
                            <street>11 Main St.</street>
                            <city>San Francisco</city>
                            <state>CA</state>
                            <zip>98765</zip>
                        </address>
                    </employee>
                    <employee ssn="789-789-7890">
                        <name first="Mary" last="Roe"/>
                        <address>
                            <street>99 Broad St.</street>
                            <city>Newton</city>
                            <state>MA</state>
                            <zip>01234</zip>
                        </address>
                    </employee>
                </employees>;
			
			
			
			private function init():void
			{
				var arr:Array=[];
				for each(var xm:XML in employees.employee)
				{
					var obj={
								name	:	xm.name.@first,
								ssn		:	xm.@ssn
								
					}
					arr.push(obj);
				}
				dg.dataProvider=arr;
			}//
		]]>
	</mx:Script>
	
</mx:Application>


now my question is.. instead of looping through the xml and then forming obj's, is there any direct way to use the tags or attributes that i want to show in the datagrid.. *note: i do not knw the number of data that comes from the server...


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 6+2 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions