Parse an XML String

hi lets say i got an XML String which looks like this..

String xmlstring = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><GET_REALIZED_GAIN_LOSS_DETAIL_RESPONSE xsi:schemaLocation=\"http://www.statementone.com/webservice/schemas D:\\PMTSchema.xsd\" xmlns=\"http://www.statementone.com/webservice/schemas\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><STATUS>true</STATUS><ERRORS><ERROR><TYPE>String</TYPE><MESSAGE>String</MESSAGE><ERROR_ID>1</ERROR_ID></ERROR><ERROR><TYPE>String</TYPE><MESSAGE>String</MESSAGE><ERROR_ID>1</ERROR_ID></ERROR></ERRORS><GET_REALIZED_GAIN_LOSS_RESULT><XYZ>String</XYZ></GET_REALIZED_GAIN_LOSS_RESULT></GET_REALIZED_GAIN_LOSS_DETAIL_RESPONSE>";

DocumentBuilderFactory factory =

DocumentBuilderFactory.newInstance();

DocumentBuilder db = factory.newDocumentBuilder();

InputSource inStream = new InputSource();

inStream.setCharacterStream(new StringReader(xmlstring));

Document doc1 = db.parse(inStream);

I notice that all the values i set in XML are available in the doc1 field. But I was not able to get them as a string..

Can Some one tell me how to get the attributes out of the doc1? I tried getElementBytag and other options.. Do i need to take out the tag items in the sequence in which they are given? or can i select a tag random and pick up the attributes?

Plzz help me out!!

[1550 byte] By [IronKnighta] at [2007-11-26 21:51:34]
# 1
You need to explain what exactly you wanted to do. Do you just want read the elements in the xml or elements with respective attributes. I guess you know attributes and elements are different.
Srini_Kandulaa at 2007-7-10 3:45:03 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hope this helps you, let me know.

String xmlstring = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>....... </GET_REALIZED_GAIN_LOSS_DETAIL_RESPONSE>";

DocumentBuilderFactory factory =

DocumentBuilderFactory.newInstance();

DocumentBuilder db = factory.newDocumentBuilder();

InputSource inStream = new InputSource();

inStream.setCharacterStream(new StringReader(xmlstring));

Document doc1 = db.parse(inStream);

NamedNodeMap attribes = doc1.getAttributes();

NodeList nodes = doc1.getChildNodes();

http://snippets.dzone.com/posts/show/3575

http://www.brics.dk/~amoeller/XML/programming/domexample.html

Message was edited by:

Srini_Kandula

Srini_Kandulaa at 2007-7-10 3:45:03 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...