其实我正在开发webservices。我已经提供了类似http://www.url.com/requesthandler.ashx.
的链接,现在我必须从此链接访问数据并将其显示在我的自定义gridView中,其中包含textView和ImageVIew。
我从XML格式获取给定URL的响应,如下所示。
<Result><Status>OK</Status><SearchedText>in</SearchedText><Books><Book><BookID>161</BookID><BookCode>EN161</BookCode><BookTitle>A Brief History of the Fourteen Infallibles</BookTitle><BookAuthor>Anonymous</BookAuthor><DatePublished>5/18/2012 12:00:00 AM</DatePublished><CPID>23</CPID><StatusID>168</StatusID><CPName>Kazim.Homayee</CPName><CPEmail>kazim.homayee@gmail.com</CPEmail><HandCoverPrice></HandCoverPrice><PDFPrice>0.00</PDFPrice><PaperBackPrice></PaperBackPrice><EPubPrice></EPubPrice><BookImage>1.jpg</BookImage><Language>English</Language><ShippingCity>Karachi</ShippingCity><ShippingState>Sindh</ShippingState><ShippingCountry>Pakistan</ShippingCountry><BookUploadPath>EN161</BookUploadPath></Book><Book><BookID>263</BookID><BookCode>EN263</BookCode><BookTitle>A Call To Divine Unity</BookTitle><BookAuthor>Mansoor L Limba</BookAuthor><DatePublished>7/17/2003 12:00:00 AM</DatePublished><CPID>23</CPID><StatusID>287</StatusID><CPName>Kazim.Homayee</CPName><CPEmail>kazim.homayee@gmail.com</CPEmail><HandCoverPrice></HandCoverPrice><PDFPrice>0.00</PDFPrice><PaperBackPrice></PaperBackPrice><EPubPrice></EPubPrice><BookImage>1.jpg</BookImage><Language>English</Language><ShippingCity>Karachi</ShippingCity><ShippingState>Sindh</ShippingState><ShippingCountry>Pakistan</ShippingCountry><BookUploadPath>EN263</BookUploadPath></Book><Book><BookID>6</BookID><BookCode>EN6</BookCode><BookTitle>A Code of Practice for Muslims in the West</BookTitle><BookAuthor>Abdul Hadi al-Hakim</BookAuthor><DatePublished>3/16/2012 12:00:00 AM</DatePublished><CPID>23</CPID><StatusID>6</StatusID><CPName>Kazim.Homayee</CPName><CPEmail>kazim.homayee@gmail.com</CPEmail><HandCoverPrice></HandCoverPrice><PDFPrice>0.00</PDFPrice><PaperBackPrice></PaperBackPrice><EPubPrice></EPubPrice><BookImage>1.jpg</BookImage><Language>English</Language><ShippingCity>Karachi</ShippingCity><ShippingState>Sindh</ShippingState><ShippingCountry>Pakistan</ShippingCountry><BookUploadPath>EN6</BookUploadPath></Book><Book><BookID>9</BookID><BookCode>EN9</BookCode><BookTitle>A DIVINCE Perspective on Rights</BookTitle><BookAuthor>Ghodratullah Mashayekhi</BookAuthor><DatePublished>3/16/2012 12:00:00 AM</DatePublished><CPID>23</CPID><StatusID>16</StatusID><CPName>Kazim.Homayee</CPName><CPEmail>kazim.homayee@gmail.com</CPEmail><HandCoverPrice></HandCoverPrice><PDFPrice>0.00</PDFPrice><PaperBackPrice></PaperBackPrice><EPubPrice></EPubPrice><BookImage>1.jpg</BookImage><Language>English</Language><ShippingCity>Karachi</ShippingCity><ShippingState>Sindh</ShippingState><ShippingCountry>Pakistan</ShippingCountry><BookUploadPath>EN9</BookUploadPath></Book><Book><BookID>247</BookID><BookCode>EN247</BookCode><BookTitle>A Divine Perspective On Rights</BookTitle><BookAuthor>Imam Sajjad Ali ibn al-Hussein</BookAuthor><DatePublished>7/12/2008 12:00:00 AM</DatePublished><CPID>23</CPID><StatusID>950</StatusID><CPName>Kazim.Homayee</CPName><CPEmail>kazim.homayee@gmail.com</CPEmail><HandCoverPrice></HandCoverPrice><PDFPrice>0.00</PDFPrice><PaperBackPrice></PaperBackPrice><EPubPrice></EPubPrice><BookImage>1.jpg</BookImage><Language>English</Language><ShippingCity>Karachi</ShippingCity><ShippingState>Sindh</ShippingState><ShippingCountry>Pakistan</ShippingCountry><BookUploadPath>EN247</BookUploadPath></Book><Book><BookID>165</BookID><BookCode>EN165</BookCode><BookTitle>A Document of Instruction by Imam Ali (as)</BookTitle><BookAuthor>Anonymous</BookAuthor><DatePublished>5/18/2012 12:00:00 AM</DatePublished><CPID>23</CPID><StatusID>185</StatusID><CPName>Kazim.Homayee</CPName><CPEmail>kazim.homayee@gmail.com</CPEmail><HandCoverPrice></HandCoverPrice><PDFPrice>0.00</PDFPrice><PaperBackPrice></PaperBackPrice><EPubPrice></EPubPrice><BookImage>1.jpg</BookImage><Language>English</Language><ShippingCity>Karachi</ShippingCity><ShippingState>Sindh</ShippingState><ShippingCountry>Pakistan</ShippingCountry><BookUploadPath>EN165</BookUploadPath></Book><Book><BookID>12</BookID><BookCode>EN12</BookCode><BookTitle>A Probe into the History of Ashura</BookTitle><BookAuthor>Dr Ibrahim Ayati</B
<BookTitle>
,<BookCode>
和<BookImage>
标记内的数据,并将其显示在textVIew和imageVIew中。< / LI>
提前感谢。
答案 0 :(得分:1)
通常,有两种解析XML的方法:
方法1的内存效率更高,Android开发人员文档建议here也是如此。
方法2通常更容易上手。但由于效率较低,因此它不是首选方法,因此在Android开发人员文档中更加隐藏。请参阅此API doc on the DocumentBuilderFactory和this tutorial以开始使用。
显示症结的片段:
public Document parseXml(String xml) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder building = factory.newDocumentBuilder();
InputSource input = new InputSource();
input.setCharacterStream(new StringReader(xml));
return builder.parse(input);
}