E4X: grab nodes with namespaces?

后端 未结 3 1632
慢半拍i
慢半拍i 2020-12-18 09:49

I want to learn how to process XML with namespaces in E4X so basically here is what I want to learn, say I have some XML like this:



        
3条回答
  •  有刺的猬
    2020-12-18 10:47

    I'm not sure whether this answers the question exactly, but given your scenario, the following code retrieves both values (given the "xml" variable, referenced below, is an XML object containing the snippet of XML code you provided):

    // Your "rdf" namespace
    namespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
    use namespace rdf;
    
    // Your "reg" (i.e, default) namespace
    namespace reg = "http://purl.org/rss/1.0/";
    use namespace reg;
    
    private function getYourValues():void
    {               
        var rdfitems:String = xml.rdf::item.@value;
        var regitems:String = xml.reg::item.@value;
    }
    

    A distinction needs to be made between the "rdf" item and the "non-rdf" one, since their element names are otherwise identical, so the second namespace is declared to allow you to retrieve each item independently. Hope it helps!

提交回复
热议问题