PDA

View Full Version : Searching PARTIAL attribute value of XML



gkp.gaurav
May 12th, 2009, 06:03 PM
I have gone thru the Kirupa's tutorial "Using XML in Flash CS3/AS3", and it helped a lot in my project. Now, I have a question in XML searching. If an attribute's value is say title="kirupa tutorial" and a user wanted to search only the word "kirupa", then how can i get this node of xml, which title is "kirupa tutorial"..

@title == "kirupa" only works when the whole word matches the value of "title" attribute, but i want to search a partial word.

gkp.gaurav
May 14th, 2009, 09:21 AM
Hey Kirupa,
Can u please help me??

Please extend your tutorial for partial word search.

kunjan
May 19th, 2009, 09:13 AM
Hello,

As per my knowledge it is not possible to search partial word in xml, but you can do one thing is that you can store whole xml data to an array then you can search in array then do further action.

let back to me if you have any query.

Regards,
Kunjan.

gkp.gaurav
May 19th, 2009, 09:37 AM
hello kunjan,
Thanks for the reply, but I have solved the problem. We can do this without using Array. You have to use Regular Expression for this. And the good news is that because of ECMA script, As3 fully support Regular Expressions.

Cheers!

kunjan
May 20th, 2009, 12:49 AM
Hello Gaurav,

can you please share the code in which you have implement search with regular expression or provide some part of code so me & others also got the idea.

Regards,
kunjan.

gkp.gaurav
May 20th, 2009, 03:30 AM
Sure. Here is the code:
(Bold texts are the changes which i have implemented in kirupa's tutorial's code)


var xmlLoader:URLLoader = new URLLoader(); var xmlData:XML = new XML(); xmlLoader.addEventListener(Event.COMPLETE, LoadXML); xmlLoader.load(new URLRequest("http://www.kirupa.com/net/files/sampleXML.xml")); function LoadXML(e:Event):void { xmlData = new XML(e.target.data); ParseBooks(xmlData); } function ParseBooks(bookInput:XML):void { var pattern:RegExp = new RegExp("Stephen", "i"); // i is used for ignoring the case.trace("XML Output"); trace("------------------------"); var authorList:XMLList = bookInput.Book.(pattern.test(author)); trace(authorList); }
Cheers!
-Gaurav :)

gkp.gaurav
May 20th, 2009, 03:39 AM
Forum's text editor is removing all coding layout convensions. Please take care, read the code carefully.

kunjan
May 20th, 2009, 04:20 AM
Hello gaurav,

I have implemented example. it works fine
Thanks & Regards,
Kunjan.

gkp.gaurav
May 20th, 2009, 07:10 AM
:)