2010-04-27 5 views
7

मैंने कई ऑनलाइन उदाहरणों में निम्नलिखित विधियों का उपयोग किया है, लेकिन किसी XML फ़ीड को पार्स करने के अनुशंसित तरीके से कोई दस्तावेज नहीं मिला है।एक्शनस्क्रिप्ट 3.0 के साथ एकाधिक नामस्थानों के साथ एक XML फ़ीड को पार्स करने का अनुशंसित तरीका क्या है?

विधि 1:

protected function xmlResponseHandler(event:ResultEvent):void 
{ 
    var atom:Namespace = new Namespace("http://www.w3.org/2005/Atom"); 
    var microsoftData:Namespace = new Namespace("http://schemas.microsoft.com/ado/2007/08/dataservices"); 
    var microsoftMetadata:Namespace = new Namespace("http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"); 

    var ac:ArrayCollection = new ArrayCollection(); 
    var keyValuePairs:KeyValuePair; 
    var propertyList:XMLList = (event.result as XML)..atom::entry.atom::content.microsoftMetadata::properties; 

    for each (var properties:XML in propertyList) 
    { 
     keyValuePairs = new KeyValuePair(properties.microsoftData::FieldLocation, properties.microsoftData::Locationid); 
     ac.addItem(keyValuePairs);  
    } 

    cb.dataProvider = ac; 
} 

विधि 2:

protected function xmlResponseHandler(event:ResultEvent):void 
{ 
    namespace atom = "http://www.w3.org/2005/Atom"; 
    namespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices"; 
    namespace m = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"; 

    use namespace d; 
    use namespace m; 
    use namespace atom; 

    var ac:ArrayCollection = new ArrayCollection(); 
    var keyValuePairs:KeyValuePair; 
    var propertyList:XMLList = (event.result as XML)..entry.content.properties; 

    for each (var properties:XML in propertyList) 
    { 
     keyValuePairs = new KeyValuePair(properties.FieldLocation, properties.Locationid); 
     ac.addItem(keyValuePairs);  
    } 

    cb.dataProvider = ac; 
} 

विधि 3:

protected function xmlResponseHandler(event:ResultEvent):void 
{ 
    var ac:ArrayCollection = new ArrayCollection(); 
    var keyValuePairs:KeyValuePair; 
    var propertyList:XMLList = (event.result as XML)..*::entry.*::content.*::properties; 

    for each (var properties:XML in propertyList) 
    { 
     keyValuePairs = new KeyValuePair(properties.*::FieldLocation, properties.*::Locationid); 
     ac.addItem(keyValuePairs);  
    } 

    cb.dataProvider = ac; 
} 

नमूना XML फ़ीड:

<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?> 
<feed xml:base="http://www.test.com/Test/my.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"> 
    <title type="text">Test_Locations</title> 
    <id>http://www.test.com/test/my.svc/Test_Locations</id> 
    <updated>2010-04-27T20:41:23Z</updated> 
    <link rel="self" title="Test_Locations" href="Test_Locations" /> 
    <entry> 
     <id>1</id> 
     <title type="text"></title> 
     <updated>2010-04-27T20:41:23Z</updated> 
     <author> 
      <name /> 
     </author> 
     <link rel="edit" title="Test_Locations" href="http://www.test.com/id=1" /> 
     <category term="MySQLModel.Test_Locations" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
     <content type="application/xml"> 
      <m:properties> 
       <d:FieldLocation>Test Location</d:FieldLocation> 
       <d:Locationid>test0129</d:Locationid> 
      </m:properties> 
     </content> 
    </entry> 
    <entry> 
     <id>2</id> 
     <title type="text"></title> 
     <updated>2010-04-27T20:41:23Z</updated> 
     <author> 
      <name /> 
     </author> 
     <link rel="edit" title="Test_Locations" href="http://www.test.com/id=2" /> 
     <category term="MySQLModel.Test_Locations" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
     <content type="application/xml"> 
      <m:properties> 
       <d:FieldLocation>Yet Another Test Location</d:FieldLocation> 
       <d:Locationid>test25</d:Locationid> 
      </m:properties> 
     </content> 
    </entry> 
</feed> 

उत्तर

1

तीसरा व्यक्ति उन्हें अनदेखा करके नामस्थान रखने के उद्देश्य को पूरी तरह से हरा देता है। तो यह एक नंबर है।

पहले दो तरीकों में से, हालांकि यह कुछ अतिरिक्त कीस्ट्रोक का कारण बन सकता है, मैं पहले व्यक्ति को पसंद करता हूं क्योंकि यह स्पष्ट रूप से बताता है कि प्रत्येक पहचानकर्ता किस नामस्थान को संदर्भित करता है।

मुझे यह भी जोड़ना होगा कि दूसरी विधि मेरे लिए नई है - अभी तक यह नहीं मिली है।

संबंधित मुद्दे