【问题标题】:How to remove all nodes of a certain type using E4X?如何使用 E4X 删除某种类型的所有节点?
【发布时间】:2015-03-23 19:35:25
【问题描述】:

我有一个 XML 实例,其中包含许多要删除的节点。我知道如何获取这些节点的列表,但我将如何删除它们?之后我将不得不向 XMLList 添加新项目。不确定这是否会改变答案。我看到 XMLList 上有一个 replace() 方法。

动作脚本:

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>

【问题讨论】:

    标签: xml actionscript-3 e4x


    【解决方案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"/>);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-18
      • 2016-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多