-1

I have like this XML in String

<?xml version='1.0' encoding='UTF-8'?><errors><error><domain>yt:quota</domain><code>too_many_recent_calls</code></error></errors>

This XML is not in file. It is in String then how i can parse it?

Regards, Girish

Girish Patel
  • 1,270
  • 4
  • 16
  • 30
  • 1
    [What have you tried?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) –  Nov 09 '11 at 13:10

2 Answers2

3

You can use the SAXParser of Android to parse this String. The InputSource you need for the XMLReader of the Parser expects an input stream, so you have to convert your String into an input stream. You can use a ByteArrayInputStream for this:

InputStream is = new ByteArrayInputStream( myString.getBytes( charset ) );

See also: How do I turn a String into a InputStreamReader in java?

http://developer.android.com/reference/javax/xml/parsers/SAXParser.html

Community
  • 1
  • 1
David Tanzer
  • 2,732
  • 18
  • 30
1

convert your string to an InputStream using ByteArrayInputStream:

String xml ="valid xml here";
InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));

dom = builder.parse(is);

Or

Check below link

Parse XML string using SAX

Community
  • 1
  • 1
Nikhil
  • 16,194
  • 20
  • 64
  • 81