
- Forum
- General Help
- XML
- If I do not know the attribute names, can I have some way to get and names & values?
-
I searched the flash help, tupps's faq and this forum's Mar to now history about "attribute" but dont seems to find the answer.
even if I dont know the node name, I can loop on child by child and see their childnode[X].nodename and .nodevalue
for attributes, if I know their name, I can use childnode[X].attributes.Name to get the value.
How about the case if I (actually the running AS in flash) dont know how many and what name is the attributes ? Is there an array to loop to get them
in Flash help XML.attributes it say
Description
===========
Collection (read-write); returns an associative array containing all attributes of the specified XML object.
However, if I trace(childnode[X].attributes[X]) it is undefined.
yes I can use childnode[X].attributes[Name] but then I have to know the attributes name again.
I am not needing it urgently but I just want to know more.
Thanks in advance for any help.
-
Senior Member
OK this is stolen **directly** from ActionScript the Definitive Guide by Colin Moock.
I would suggest you go buy it as it will solve so many problems for. Did anyone ever mention this book is better than the ActionScript reference! (some claim it is the ActionScript Reference).
anyway the code:
(page 607)
var count = 0;
for (var prop in theNode.attributes)
{
trace("attribute " + prop + " has the value " + theNode.attributes[prop]);
count++;
}
trace ("the node has " + count + " attributes.");
Once again I urge you to buy this book, it is a supurb reference and will teach you everything you need to know (plus way much more) about Flash and Actionscript.
Thanks
Luke
-
Thanks! I go to book store now !!
-
The shopkeeper say this book is too old.
Now everyone looking for MX book so they will wait for MX verion of the book.....
-
delete attribute in flash
maybe I am asking too much...
I want to know also if there is a way to delete attributes.
I ask so many becasue I am writing local XML database engine which both the data structure and data store in the XML file, so that user not only able to edit data but also edit structure.
Now I forsee 2 theorotically workable but pratical problems :
1. I read from other post that the newly added nodes' ID is not reconized by flash (seems that flash didnt add the pointer link in its ID list).
2. If ppl add record / delete record, add node and delete node can do, if they add field, add a attribute to all isnt a problem, but if they want to delete field, it seems I cannot find a way to delete attribute in flash...
I have tried set the value to null / NIL with no success
I have also tried array method such as splice/pop also cant
while I can left the attribute with "" but it is definately a waste of resorces.
Thanks
-
the id problem work around
I just find a work around for the adding new nodes problem. Maybe all ppl know except me but just in case.
Code:
myXML = new XML();
theNode = myXML.createElement("Test");
theNode.attributes.A1 = "A1";
theNode.attributes.id = "QQ";
myXML.appendChild(theNode);
trace(myXML["QQ"].attributes["A1"]) //undefind
myXML.parseXML(myXML);
trace(myXML["QQ"].attributes["A1"]) //A1
Well, it is surely not a good way to reparse the XML especially if it is a large XML, so if there is better way I would like to know too 
Thanks
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
|