Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

xml - E4X: grab nodes with namespaces?

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:

<rdf:RDF 
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns="http://purl.org/rss/1.0/">
    <rdf:item value="5"/>
    <item value="10"/>
</rdf:RDF>

How could I assign <rdf:item/> to a var called rdfItems and <item/> to a var called regItems?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you have a XML that contains multiple names but you don't care about the namespaces when getting values from the XML you can do the following....

Example XML

<ns1:Item>
  <ns1:ItemType>Printed Material</ns1:ItemType>
  <ns2:Book isbn="123456">
    <ns2:Author>
      <ns2:FirstName>James</ns2:FirstName>
      <ns2:LastName>Smith</ns2:LastName>
    </ns2:Author>
    <ns2:Title>The Book Title</ns2:Title>
  </ns2:Book>
<ns1:Item> 

You could get any item regardless of namespace like this

var itemType:String = xml.*::ItemType;
var bookISBN:Number = xml.*::Book.@isbn;
var bookTitle:String = xml.*::Book.Title;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

2.1m questions

2.1m answers

60 comments

57.0k users

...