Frage

I have a simple example

var myXML:XML =
<root>
    <element type="a">I am a</element>
    <element type="b">I am b</element>
</root>
;

I cant work out how I can programatically remove an element of a specific type

delete myXML.root.element.type['a'][0];
War es hilfreich?

Lösung

To remove a XML element by matching an attribute of that element, I believe you're looking for:

var index:int = myXML.element.(@type=="b").childIndex();
delete myXML.element[index];

Based upon your XML:

var myXML:XML =
    <root>
        <element type="a">I am a</element>
        <element type="b">I am b</element>
    </root>;

After calling this function, the XML would be:

<root>
  <element type="a">I am a</element>
</root>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top