Search This Blog

Monday, 26 October 2009

Get Namepaces and find uri of prefix

Problem:
  • You have an XML with a lot of namespaces 
  • you need to create namespace Objects for a prefix
  • the namespace uri could change in different environements
Solution
  1. Get all Namespaces:

    var namespaces : Array = _xformsData.namespaceDeclarations();  

  2. Loop them and search for the prefix and save the namespace:

    var ns:Namespace;
    var i:int = namespaces.length;
    while(i--){
                    if(namespaces[i].prefix == 'xforms'){
                        ns = new Namespace(namespaces[i].prefix,namespaces[i].uri);
                        break;
                    }
                }

No comments:

Post a Comment