E4X : Retrieving a sibling of a node
One of the advantages of XML is that you can easily represent related information with a parent / child relationship. This makes it easy to parse, and understand. However, some XML formats (such as Apple's plist format), represent relationships via proximity on the same level. For example, one way to represent name / value pairs in XML could be:
[code]
Comments
-
Maybe Apple was trying to implement a generic parser so that they can add key/value pairs to the XML file at a later date that were not yet known. I agree that their method does pose some parsing difficulties. A method I've used in the past when I had XML that was not yet known was to make the key and value attributes of the same node. This way I could keep a strict relationship between the two. A third attribute was for type casting. This is what my XML file might have looked like: [code] [/code]My generic parser would go through all of the default nodes and add each one as a key/value pair to a LoadVars variable using the type attribute to properly cast the value. I was using Flash 7 so LoadVars worked nicely as a Dictionary. Then, as I started to tweak the XML file with additional defaults, I never had to go back to change the parser.