Does anyone kno开发者_开发技巧w 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?
use RegExp in your xml query, and have it case insensitive
const list:XMLList = xml.*.(@name.toString().search( new RegExp("hello", "i") )!= -1);
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.
This seems to work for me:
var lowerCasePropertyName:String = propertyName.toLowerCase();
var xmlItem:XMLList = xml.*.(attribute("name").toString().toLowerCase()==lowerCasePropertyName);
精彩评论