06-20-2003, 12:51 AM
|
#1
|
|
Buzzed off Mt. Dew
Join Date: Jun 2003
Location: Newport Beach, CA
Posts: 240
|
XML Simple Array
Because I am working on this and others are probably curious too... I found a well explained example that should help you get your XML data put together perfectly... if you are unfortunate enough to be working with XML.
http://proto.layer51.com/d.aspx?f=611
|
|
|
06-20-2003, 01:15 AM
|
#2
|
|
Master of Nothing
Join Date: Dec 2002
Location: San Diego, CA
Posts: 2,468
|
There are also several others in this forum, search on XML and you shall find some of them with enough persistence.
|
|
|
06-20-2003, 01:39 AM
|
#3
|
|
Buzzed off Mt. Dew
Join Date: Jun 2003
Location: Newport Beach, CA
Posts: 240
|
Yeah, hopefully fellow users of this forum will find your XML parser and find it perfect for their needs. The code that you supplied could probably fetch a dollar or two from what I have seen elsewhere.
Unfortunately, it was just a bit over my head and despite my efforts could not get to work for me. I think I may have offended you too because I never got much help figuring it out.
But this link gives a lot of information and even provides an example use that explains things in great depth. Hopefully someone trying to figure out the whole Flash/XML thing can use your information as well as the info supplied at this link to get things working for them.
BTW, I still don't have it up and running for me but it's starting to come around I think. That is probably what you need to do anyways... bash your head into the monitor long enough that things start to become clear. Kinda like beer goggles... but not.
|
|
|
06-20-2003, 01:51 AM
|
#4
|
|
Master of Nothing
Join Date: Dec 2002
Location: San Diego, CA
Posts: 2,468
|
No you couldn't have offended me, but possibly my ADD made me forget about the post. What thread was that in, maybe I can look at it again. But hurry because I might forget we had this conversation in say, an hour
|
|
|
06-20-2003, 02:14 AM
|
#6
|
|
Master of Nothing
Join Date: Dec 2002
Location: San Diego, CA
Posts: 2,468
|
Well for the first one, this is getting a little crazy, but I think its working properly. I think it adds one too many levels of complexity though.
ActionScript Code:
cXML = new XML();
cXML.ignoreWhite = true;
cXML.onLoad = function(s) {
if(s) {
parseMe(this);
}
};
cXML.load("CyanMenu.xml");
function parseMe(obj) {
objName = obj.firstChild.nodeName;
_root[objName] = [];
total = obj.firstChild.childNodes.length;
traverseNode(obj.firstChild, _root[objName]);
}
function traverseNode(node, ref) { //Returns Object
cnt++;
node = node.childNodes;
for(var i=0;i<node.length;i++) {
var tmpObj = {};
var foo = node[0].nodeName;
tmpObj[foo] = {};
tmpObj[foo].attributes = node[i].attributes;
if(node[i].childNodes[0].nodeType == 3) {
tmpObj[foo][node[i].nodeName] = {};
tmpObj[foo][node[i].nodeName] = node[i].firstChild.nodeValue;
ref.push(tmpObj);
}
else if(node[i].hasChildNodes() && node[i].childNodes[0].nodeType != 3) {
tmpObj[foo][node[i].childNodes[0].nodeName] = [];
ref.push(tmpObj);
traverseNode(node[i], tmpObj[foo][node[i].childNodes[0].nodeName]);
}
else {
ref.push(tmpObj);
}
}
if(cnt == total) {
trace ("Parsing finsihed");
//Do soemthing
trace (_root.menu[0].item.subItem[0].subItem.subItem[0].subItem.subItem[0].subItem.attributes.label);
}
}
The xml
Code:
<?xml version="1.0" ?>
<menu>
<item label="Programs" type="Folder">
<subItem label="Accessaries" type="Folder">
<subItem label="Accessibility" type="Folder">
<subItem label="Etc1" type="Menu"/>
<subItem label="Etc2" type="Menu"/>
</subItem>
<subItem label="Communications" type="Folder"/>
<subItem label="Entertainment" type="Folder"/>
<subItem label="Games" type="Folder"/>
<subItem label="System Tools" type="Folder"/>
<subItem label="Calculator" type="Menu"/>
<subItem label="Command Prompt" type="Menu"/>
<subItem label="Imaging" type="Menu"/>
<subItem label="NotePad" type="Menu"/>
<subItem label="Paint" type="Menu"/>
<subItem label="WordPad" type="Menu"/>
</subItem>
<subItem label="Administrative Tools" action="String">
<subItem label="Component Services" type="Menu"/>
<subItem label="Computer Management" type="Menu"/>
<subItem label="Data Sources (ODBC)" type="Menu"/>
<subItem label="Event Viewer" type="Menu"/>
<subItem label="Internet Services Manager" type="Menu"/>
<subItem label="Local Security Policy" type="Menu"/>
<subItem label="Microsoft .NET Framework Configuration" type="Menu"/>
<subItem label="Microsoft .NET Framework Wizards" type="Menu"/>
<subItem label="Performance" type="Menu"/>
<subItem label="Personal Web Manager" type="Menu"/>
<subItem label="Server Extensions Administrator" type="Menu"/>
<subItem label="Services" type="Menu"/>
<subItem label="Telnet Server Administration" type="Menu"/>
</subItem>
<subItem label="Communication" action="String"/>
<subItem label="Graphics" action="String"/>
<subItem label="Utilities" action="String"/>
</item>
<item label="Documents" type="Menu"/>
<item label="Settings" type="Folder">
<subItem label="Control Panel" action="String"/>
<subItem label="Network and Dialup Connections" action="String"/>
<subItem label="Printers" action="String"/>
<subItem label="Taskbar & Startmenu"/>
</item>
<item label="Search" type="Folder">
<subItem label="INFORMATION"/>
<subItem label="BOOKINGS"/>
</item>
<item label="Contact" type="Folder">
<subItem label="For Files or Folders..."/>
<subItem label="On the Internet..."/>
<subItem label="Using Microsoft Outlook..."/>
<subItem label="For People..."/>
</item>
<item label="Run..." type="Menu"/>
<item label="Shut Down..." type="Menu"/>
</menu>
|
|
|
06-20-2003, 02:16 AM
|
#7
|
|
Master of Nothing
Join Date: Dec 2002
Location: San Diego, CA
Posts: 2,468
|
Hold ON Hold On, I think this one is much better.
ActionScript Code:
cXML = new XML();
cXML.ignoreWhite = true;
cXML.onLoad = function(s) {
if(s) {
parseMe(this);
}
};
cXML.load("CyanMenu.xml");
function parseMe(obj) {
objName = obj.firstChild.nodeName;
_root[objName] = {};
_root[objName][obj.firstChild.childNodes[0].nodeName] = [];
total = obj.firstChild.childNodes.length;
traverseNode(obj.firstChild.childNodes, _root[objName][obj.firstChild.childNodes[0].nodeName]);
}
function traverseNode(node, ref) { //Returns Object
cnt++;
for(var i=0;i<node.length;i++) {
var tmpObj = {};
tmpObj.attributes = node[i].attributes;
if(node[i].childNodes[0].nodeType == 3) {
tmpObj[node[i].nodeName] = {};
tmpObj[node[i].nodeName] = node[i].firstChild.nodeValue;
ref.push(tmpObj);
}
else if(node[i].hasChildNodes() && node[i].childNodes[0].nodeType != 3) {
tmpObj[node[i].childNodes[0].nodeName] = [];
ref.push(tmpObj);
traverseNode(node[i].childNodes, tmpObj[node[i].childNodes[0].nodeName]);
}
else {
ref.push(tmpObj);
}
}
if(cnt == total) {
trace ("Parsing finsihed");
//Do soemthing
trace (_root.menu.item[0].subItem[1].attributes.label);
}
}
|
|
|
06-20-2003, 02:19 AM
|
#8
|
|
Master of Nothing
Join Date: Dec 2002
Location: San Diego, CA
Posts: 2,468
|
Oh sorry one more time, to account for actual node values instead of merely attributes
ActionScript Code:
cXML = new XML();
cXML.ignoreWhite = true;
cXML.onLoad = function(s) {
if(s) {
parseMe(this);
}
};
cXML.load("CyanMenu.xml");
function parseMe(obj) {
objName = obj.firstChild.nodeName;
_root[objName] = {};
_root[objName][obj.firstChild.childNodes[0].nodeName] = [];
total = obj.firstChild.childNodes.length;
traverseNode(obj.firstChild.childNodes, _root[objName][obj.firstChild.childNodes[0].nodeName]);
}
function traverseNode(node, ref) { //Returns Object
cnt++;
for(var i=0;i<node.length;i++) {
var tmpObj = {};
tmpObj.attributes = node[i].attributes;
if(node[i].childNodes[0].nodeType == 3) {
tmpObj.value = node[i].firstChild.nodeValue;
ref.push(tmpObj);
}
else if(node[i].hasChildNodes() && node[i].childNodes[0].nodeType != 3) {
tmpObj[node[i].childNodes[0].nodeName] = [];
ref.push(tmpObj);
traverseNode(node[i].childNodes, tmpObj[node[i].childNodes[0].nodeName]);
}
else {
ref.push(tmpObj);
}
}
if(cnt == total) {
trace ("Parsing finsihed");
//Do soemthing
trace (_root.menu.item[0].subItem[0].subItem[0].subItem[0]);
}
}
Code:
<?xml version="1.0" ?>
<menu>
<item label="Programs" type="Folder">
<subItem label="Accessaries" type="Folder">
<subItem label="Accessibility" type="Folder">
<subItem label="Etc1" type="Menu">foo</subItem>
<subItem label="Etc2" type="Menu"/>
</subItem>
<subItem label="Communications" type="Folder"/>
<subItem label="Entertainment" type="Folder"/>
<subItem label="Games" type="Folder"/>
<subItem label="System Tools" type="Folder"/>
<subItem label="Calculator" type="Menu"/>
<subItem label="Command Prompt" type="Menu"/>
<subItem label="Imaging" type="Menu"/>
<subItem label="NotePad" type="Menu"/>
<subItem label="Paint" type="Menu"/>
<subItem label="WordPad" type="Menu"/>
</subItem>
<subItem label="Administrative Tools" action="String">
<subItem label="Component Services" type="Menu"/>
<subItem label="Computer Management" type="Menu"/>
<subItem label="Data Sources (ODBC)" type="Menu"/>
<subItem label="Event Viewer" type="Menu"/>
<subItem label="Internet Services Manager" type="Menu"/>
<subItem label="Local Security Policy" type="Menu"/>
<subItem label="Microsoft .NET Framework Configuration" type="Menu"/>
<subItem label="Microsoft .NET Framework Wizards" type="Menu"/>
<subItem label="Performance" type="Menu"/>
<subItem label="Personal Web Manager" type="Menu"/>
<subItem label="Server Extensions Administrator" type="Menu"/>
<subItem label="Services" type="Menu"/>
<subItem label="Telnet Server Administration" type="Menu"/>
</subItem>
<subItem label="Communication" action="String"/>
<subItem label="Graphics" action="String"/>
<subItem label="Utilities" action="String"/>
</item>
<item label="Documents" type="Menu"/>
<item label="Settings" type="Folder">
<subItem label="Control Panel" action="String"/>
<subItem label="Network and Dialup Connections" action="String"/>
<subItem label="Printers" action="String"/>
<subItem label="Taskbar & Startmenu"/>
</item>
<item label="Search" type="Folder">
<subItem label="INFORMATION"/>
<subItem label="BOOKINGS"/>
</item>
<item label="Contact" type="Folder">
<subItem label="For Files or Folders..."/>
<subItem label="On the Internet..."/>
<subItem label="Using Microsoft Outlook..."/>
<subItem label="For People..."/>
</item>
<item label="Run..." type="Menu"/>
<item label="Shut Down..." type="Menu"/>
</menu>
|
|
|
06-20-2003, 03:13 AM
|
#9
|
|
Super Moderator
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
|
Hehe... I love to my name mentioned alot here...
I especially love this word... 'cXML'... Don't I look like something special???
Maybe I'll need to create another nick with it...
Thanks for sharing great information, guys... Much appreciated...
|
|
|
06-20-2003, 03:15 AM
|
#10
|
|
Master of Nothing
Join Date: Dec 2002
Location: San Diego, CA
Posts: 2,468
|
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 05:15 AM.
///
|
|