2012-08-24 27 views
0

我爲我的在線網站製作了一些Flash文件(.xml)。現在我想在我的android應用程序的這些XML文件中的數據。我怎麼能做到這一點。這些xml文件格式很好,整潔而且寫得很好。 這是一個xml文件的一些代碼,在其他所有文件中也是幾乎相同的。如何解析android中爲flash編寫的xml文件中的數據?

<slide id="2" template="listeningStayMultiText"> 
    <images> 
     <image direction="Right" xCord="100" yCord="170"><![CDATA[images/common/1x1.gif]]></image> 
    </images> 
    <sentences> 
     <sentence index="1" fontColor="0x000000" width="600" height="70" size="18" xPos="50" yPos="20" bgColor="0xDBEFDF" borderColor="0x006600" align="left"><![CDATA[<br/> Let’s look at how we make negative sentences in the simple present tense -]]></sentence> 
     <sentence index="2" fontColor="0xffffff" width="300" height="60" size="18" xPos="50" yPos="100" bgColor="0x006600" borderColor="0x000000" align="center"><![CDATA[<br/>POSITIVE SENTENCE]]></sentence> 
     <sentence index="3" fontColor="0xffffff" width="300" height="60" size="18" xPos="350" yPos="100" bgColor="0x006600" borderColor="0x000000" align="center"><![CDATA[<br/>NEGATIVE SENTENCE]]></sentence> 
     <sentence index="4" fontColor="0x000000" width="300" height="120" size="18" xPos="50" yPos="160" bgColor="0xDBEFDF" borderColor="0x000000" align="center"><![CDATA[<br/>I play football]]></sentence> 
     <sentence index="5" fontColor="0x000000" width="300" height="120" size="18" xPos="350" yPos="160" bgColor="0xDBEFDF" borderColor="0x000000" align="center"><![CDATA[<br/>I <b>do not</b> play football<br/>OR<br/>I <b>don't</b> play football]]></sentence> 
     <sentence index="6" fontColor="0x000000" width="600" height="90" size="18" xPos="50" yPos="300" bgColor="0xDBEFDF" borderColor="0x000000" align="center"><![CDATA[<br/>We use '<b>do not</b>' or '<b>don’t</b>' with ‘<b>I</b>’ to make negative sentences in the simple present tense.]]></sentence> 
    </sentences> 
    <audio><![CDATA[images/common/silence.mp3]]></audio>   
    <bgImage><![CDATA[images/bg.jpg]]></bgImage> 
</slide> 
+0

使用'XmlPullParser'。 http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html – biegleux

回答

0

看看在Simple framework

它使用註解與您的數據模型,它很容易實現。 在你的情況下,它看起來像

@Root 
public class Slide { 
    @Attribute 
    public int id; 
    @Attribute 
    public String template; 
    @ElementList 
    public List<Images> image; 
    @ElementList 
    public List<Sentence> sentences; 

} 

等等