Solved

Dynamic Multi-Level Objects?

Posted on 2007-11-28
3
140 Views
Last Modified: 2012-06-27
I'm trying to create an array to hold the values from an XML file. The file mostly contains name/value pairs, but some of the nodes contain attributes. I'd like to store the results in an object with a format similar to this:

object.nodeName
object.nodeName.attribute1
object.nodeName.attribute2

I'm doing fine with generating the first level - the object.nodeName, but I keep getting "undefined" when I try to create the attribute. Here's the code I have so far:
function popObj(tempXML,tempObj) {
	for (var i=0; i<tempXML.childNodes.length; i++) {
		if (tempXML.childNodes[i].childNodes[0].nodeValue != undefined) {
			tempObj[tempXML.childNodes[i].nodeName] = tempXML.childNodes[i].childNodes[0].nodeValue;
			for (var j in tempXML.childNodes[i].attributes) {
				tempObj[tempXML.childNodes[i].nodeName][j] = tempXML.childNodes[i].attributes[j];				
			}	
		}
	}
}

Open in new window

0
Comment
Question by:katyjack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
Rob earned 250 total points
ID: 20475979
this will parse your xml into variables and arrays

https://filedb.experts-exchange.com/incoming/ee-stuff/6131-XMLParser.zip
0
 

Author Closing Comment

by:katyjack
ID: 31415462
Thanks - I've seen similar parsers before but I'm trying to teach this to myself so I was trying to write it on my own - I can use this to get the job done and look at the code to see how they did it.

Thanks -
0
 
LVL 43

Expert Comment

by:Rob
ID: 20488117
to be honest I wouldn't have written it if I'd found one already as it got quite complicated with all the recursion etc. but I can understand you wanting to understand how it works.  I've just included attributes as well so if you want an updated copy let me know :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question