views:

208

answers:

2

Does anyone know of a trick to ignore upper/lower/camelcase on XML node names and attributes?

A quick example: I give an XML file to my client which contains an XML attribute named fooID but the client could change the XML, and - not being aware of upper/lowercaseness change or add an attribute under 'fooid'. Naturally my parser (in AS3) would ignore the all lowercase attribute. Note that the value contained in fooID isn't the problem here but the attribute name itself. Any ideas?

A: 

You could write your own XML parser (the old, pre-E4X way), in which you loop through all nodes recursively, look for the node names of your choice, and then write out an object graph or store the parsed XML in other ways. This involves testing each node name against any allowed node name (pseudo code: if nodename == "fooID" then do something with the node). Because you're iffing on each node, you can normalize the matching by lowercasing both nodename and "fooID".

Cumbersome, but does the trick.

Niko Nyman