如何在android中解析本地XML数据?
我喜欢字符串中的XML如何在android中解析本地XML数据?,android,xml-parsing,Android,Xml Parsing,我喜欢字符串中的XML <?xml version='1.0' encoding='UTF-8'?><errors><error><domain>yt:quota</domain><code>too_many_recent_calls</code></error></errors> 此XML不在文件中。它在串中 那么我如何解析它呢 问候,, Girish使用ByteArrayInputS
<?xml version='1.0' encoding='UTF-8'?><errors><error><domain>yt:quota</domain><code>too_many_recent_calls</code></error></errors>
此XML不在文件中。它在串中
那么我如何解析它呢
问候,,
Girish使用ByteArrayInputStream将字符串转换为输入流:
String xml ="valid xml here";
InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
dom = builder.parse(is);
或
检查下面的链接
您可以使用Android的SAXParser来解析此字符串。解析器的XMLReader所需的InputSource需要输入流,因此必须将字符串转换为输入流。您可以为此使用ByteArrayInputStream:
InputStream is = new ByteArrayInputStream( myString.getBytes( charset ) );
另见: