2012-02-23 100 views
0

是否可以使用SAX解析器解析xml文件中的屬性?在android中使用SAX解析屬性

恩:我能夠輕鬆地分析:

<author>Hina2</author> 

結果:Hina2

如何解析屬性從:

<text author="Hina2" timeModified="timestampgoeshere" 
pos="pre" priority="0" thumbUrl="text2" url="textfull2"/> 

謝謝!

回答

0

startElement方法將Attributes作爲參數。您可以從該參數獲取元素的屬性。你可以參考這個鏈接example

0

如果您使用了Android版本的SAX,那麼你可以去像這樣

text.setStartElementListener(new StartElementListener(){ 
       public void start(Attributes attr) 
       { 
        String value = attr.getValue("author"); 

        currentMessage.setAuthor(value.toString()); 
       } 
     });