我有一个XML实例,它有许多我想删除的节点。我知道如何获取这些节点的列表,但我将如何删除它们?之后我将不得不向XMLList添加新项。不确定是否会改变答案。我看到XMLList上有一个replace()方法。
ActionScript:
var xmllist:XMLList = myXML.Hyperlink;
XML:
<Document>
<HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//test.com#1stMultilineLink/" DestinationUniqueKey="1" Name="http://test.com#1stMultilineLink/" DestinationURL="http://test.com#1stMultilineLink/" Hidden="false"/>
<HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//test.com#inlinehyperlink_noshareddestination" DestinationUniqueKey="2" Name="http://test.com#inlinehyperlink_noshareddestination" DestinationURL="http://test.com#inlinehyperlink_noshareddestination" Hidden="true"/>
<HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//google.com#multilinehyperlink" DestinationUniqueKey="3" Name="http://google.com#multilinehyperlink" DestinationURL="http://google.com#multilinehyperlink" Hidden="false"/>
<Hyperlink Self="ufc" Name="is a multiline hyperlink that terminates here" Source="uf9" Visible="false" Highlight="None" Width="Thin" BorderStyle="Solid" Hidden="false" DestinationUniqueKey="1">
<Properties>
<BorderColor type="enumeration">Black</BorderColor>
<Destination type="object">HyperlinkURLDestination/http%3a//test.com#1stMultilineLink/</Destination>
</Properties>
</Hyperlink>
<Hyperlink Self="u112" Name="hyperlink inline" Source="u111" Visible="false" Highlight="None" Width="Thin" BorderStyle="Solid" Hidden="false" DestinationUniqueKey="2">
<Properties>
<BorderColor type="enumeration">Black</BorderColor>
<Destination type="object">HyperlinkURLDestination/http%3a//test.com#inlinehyperlink_noshareddestination</Destination>
</Properties>
</Hyperlink>
<Hyperlink Self="u137" Name="another multline hyperlink" Source="u136" Visible="false" Highlight="Outline" Width="Thick" BorderStyle="Solid" Hidden="false" DestinationUniqueKey="3">
<Properties>
<BorderColor type="enumeration">Purple</BorderColor>
<Destination type="object">HyperlinkURLDestination/http%3a//google.com#multilinehyperlink</Destination>
</Properties>
</Hyperlink>
</Document>
答案 0 :(得分:1)
行。我找到了一些方法。
方法1.使用XMLListCollection。这似乎从原始XML中删除了项目:
var hyperlinksList:XMLList = myXML.Hyperlink;
var myXMLListCollection:XMLListCollection = new XMLListCollection(hyperlinksList);
myXMLListCollection.removeAll();
方法2.直接从XML中删除节点:
delete myXML.Hyperlink;
然后我可以使用XMLListCollection.addItem():
再次添加它们myXMLListCollection.addItem(<Hyperlink id="mylink"/>);