A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Help with Flash/XPath

  1. #1
    Junior Member
    Join Date
    Nov 2004
    Posts
    7

    Help with Flash/XPath

    Forgive me for asking what is probably a very simple question, but it's been so long since I've done much in flash that I'm a bit rusty. Something tells me I used to know how to do this, but for the life of me, I can't remmeber....

    I'm building an application in flash (using the XPath libraries from www.xfactorstudio.com) for customers to design their own custom computer. The plan is to have several "base" systems that can be loaded into the app then they will be able to customize the system by selecting different components from menus, etc. All the data will be stored in XML files, a different file for each type of component (that will then include details for each variation of said component that we carry), and a set of XML files for the 'base" systems, and finally, one controller XML file to tell the app which files belong to which groups, etc.

    All of that is probably more info than you need to answer this question, but hey, I'm really excited about building this.

    Sooo, anyway, on to the problem. Let me give you an example of my XML for a base computer system.

    Code:
    <computer>
    	<info>
    		<name>Test Computer One</name>
    		<base>200</base>
    		<image>images/test.jpg</image>
    	</info>
    	<hardware>
    		<motherboard>
    			<name>MB 1</name>
    			<price>100</price>
    			<specs>MB Specs</specs>
    		</motherboard>
    	</hardware>
    </computer>
    Alright, so now I'm grabbing the XML data in Flash like so....

    Code:
    pc.onLoad = function() {
    	pcInfo = pc.selectNodes("//info");
    	trace(pcInfo);
    }
    This returns:

    Code:
    <info>
    	<name>Test Computer One</name>
    	<base>200</base>
    	<image>images/test.jpg</image>
    </info>
    Makes sense, right?

    Now, how do I pull just one element out of that, i.e. "name" ?

    I don't want to have to go grabbing them all indivudally, like so

    Code:
    pcName = pc.selectNodes("//info/name");
    pcBase = pc.selectNodes("//info/base");
    pcImage = pc.selectNodes("//info/name");
    I'm trying to avoid that... I would much rather just grab the data out of a parent array, i.e. "pcInfo" as needed.

    But there's only one problem.....

    How? I can't remember.

  2. #2
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    Why don't you want to grab them individually?

    You need to assign them to something anyway?

    Or are you trying to build an array of data?

    Not sure exactly what you question is.

    Thanks

    Luke
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

  3. #3
    Junior Member
    Join Date
    Nov 2004
    Posts
    7
    Yah, sorry if I wasn't quite clear on that. I want to build an array of data. The reason being that there will be so much stuff that I just thought it would be easier and more efficient to manage than having to go through the XML line by line, basically, and assign everything to variables. So instead of having to set "name" "price" and "specs" for every single hardware component, I could just just have an array of hardware and then return hardware['motherboard']['name'], hardware['motherboard']['price'], hardware['monitor'][name'], etc. when I'm outputting things.

    Also, I think I may have just answered my own question, or found a reasonable alternative. Since I can just make 3 arrays (name, price, specs) and then as long as the array keys match, it'll all work together. i.e. name[o] = "motherboard", price[0] = "motherboard price", specs[0] = "motherboard specs"

    *sigh* Now I DO feel stupid. LOL Don't know why I didn't think of that yesterday, guess I just needed a break from it/different perspective.

    Thanks for your time/help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center