-
I'm trying to read an XML document with this structure
Code:
substitute the * with < and > (case you hadn't figured that one out yet ;-)
*? xml etc*
*list*
*member*
*id*12345*/id*
*name*John Doe*/name*
*/member*
*/list*
(btw why won't the post display my tags when I use < >?)
but what 's the correct syntax (using the xml object) to read this? I've gotten so far as to declare the XML object, and have it call a function when onLoad. The function itself:
member = myXML.firstChild.firstChild;
id = member.firstChild;
name = id.nextSibling;
var1 = name.toString();
which puts "*name*John Doe*/name*" in my variable - what am I doing wrong ?
JJ
-
Im pretty new to XML myself, but have you tried
*member*
*member id = "1234"
name = "john doe"/*
*member id = "3456"
name = "fred smith"/*
*/member*
hope it helps
Andy
-
OK but not what I really want ...
Originally posted by andyj
Im pretty new to XML myself, but have you tried
*member*
*member id = "1234"
name = "john doe"/*
*member id = "3456"
name = "fred smith"/*
*/member*
hope it helps
Andy
Ok I admit using attributes is easier, but I don't want to (some of the data wouldn't be suitable to be used as attributes).
Jef
-
if you change your xml document to look like this:
Code:
<list><member><id>12345</id><name>John Doe</name></member></list>
(basically i removed the xml declaration tag, which isnt required)
You can use this code to grab the name and id:
Code:
myxml=new XML()
myxml.load("yourxmlfile.xml")
myxml.onLoad=parse
function parse(loaded){
if(loaded){
id=myxml.firstChild.firstChild.firstChild.firstChild.nodeValue
name=myxml.firstChild.firstChild.firstChild.nextSibling.firstChild.nodeValue
}
}
-
Originally posted by FlashGuru
if you change your xml document to look like this:
Code:
<list><member><id>12345</id><name>John Doe</name></member></list>
(basically i removed the xml declaration tag, which isnt required)
You can use this code to grab the name and id:
Code:
myxml=new XML()
myxml.load("yourxmlfile.xml")
myxml.onLoad=parse
function parse(loaded){
if(loaded){
id=myxml.firstChild.firstChild.firstChild.firstChild.nodeValue
name=myxml.firstChild.firstChild.firstChild.nextSibling.firstChild.nodeValue
}
}
Ok, I'm sorry to open this thread again,
but .... what I don't understand is this: id=myxml.firstChild.firstChild.firstChild.firstChi ld
4 X firstChild ??
Perhaps you're willing to explain to me what the very first firstChildNode is ?
-
Ah, ok, got it now (finally)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|