0

How can I retrieve the properties of an xml tag independent of whether the property name is written in capital letters or not?

currently i do something like:

myXML = new XML(...);
if(myXML.@PROPERTYNAME.length())
    //...do something with myXML.@PROPERTYNAME...
if(myXML.@propertyname.length())
    //...do the same thing with myXML.@propertyname...

But I guess there is an easier way to capture properties independent of how they are written? How?

Juergen
  • 12,378
  • 7
  • 39
  • 55
Mat
  • 4,281
  • 9
  • 44
  • 66
  • possible duplicate of [Ignoring case on E4X node names and attributes?](http://stackoverflow.com/questions/2140055/ignoring-case-on-e4x-node-names-and-attributes) – Adam Harte Jun 24 '12 at 23:42

2 Answers2

0

The best solution would be to set a standard for your XML and stick to it so that your attributes are all formed consistently. If this is not an option then you could just do multiple searches. Not the prettiest solution but might do the job.

Pass the attribute name as a String to a method that searches for it in both upper and lower case and returns the combined results.

    private function onLoaded(e:Event):void
    {
        xml = new XML(e.target.data);

        var list:XMLList = getNodesByAttribute("att");
        trace(list[1]);
    }

    private function getNodesByAttribute(attributeID:String):XMLList
    {
        var list:XMLList = (xml..@[attributeID.toLowerCase()]) + (xml..@[attributeID.toUpperCase()]);
        return list;
    }

If your attributes are not only all upper and all lower case (ATTRIBUTE, attribute AND Attribute) then this will get messy and won't help.

Maybe you could push the idea further using a regular expression but I'm afraid I am no good at regex (not even sure if it can be used in this situation).

popClingwrap
  • 3,919
  • 5
  • 26
  • 44
0

why not use reg exp:

const list:XMLList = xml.*.(@name.toString().search( new RegExp("hello") )!= -1);
neil manuell
  • 225
  • 2
  • 10