-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

1
  • 1
    What have you tried? Commented Nov 9, 2011 at 13:10

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.