is supported in part by

July 02, 2008

convert xml tags to lowercase

Here's a handy little function for converting all tag names and attribute names in an XML object to lower case. Useful for doing case-insensitive matching on tag names and attribute names.

public function xmlTagsToLowerCase (xml:XML):XML {
  // Convert the root tag to lowercase
  for each (var attribute:XML in xml.@*) {
  // Convert all descendant tags to lowercase
  for each (var child:XML in xml..*) {
    // If the node is an element...
    if (child.nodeKind() == "element") {
      // ...change its name to uppercase.
      // If the node has any attributes, change their names to uppercase.
      for each (attribute in child.@*) {
  return xml;
// Usage:
var x:XML = xmlTagsToLowerCase(new XML ("<A C='D'><B>test</B></A>"));
trace(x); // Output: <a c="D"><b>test</b></a>
Posted by moock at July 2, 2008 09:49 PM