Skip to main content

Parsing a String

6 replies [Last post]
qwertyscar
Offline
Joined: 2008-04-16
Points: 0

For my thesis project, I need to exchange data using Strings in XML format, is there a way to change a Document to a String and vice-versa? I tried the always helpful toString method but I didn't get the desidered results
thanks for the attention
Marco Scarpa

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
qwertyscar
Offline
Joined: 2008-04-16
Points: 0

I got the half of the answer, I asked also the next part

Message was edited by: qwertyscar

joehw
Offline
Joined: 2004-12-15
Points: 0

Same process. Just the other way around, using a StringReader.

qwertyscar
Offline
Joined: 2008-04-16
Points: 0

I found easier in this way, using a ByteArrayInputStream:

ByteArrayInputStream stream=new ByteArrayInputStream(toShow.getBytes());
doc=builder.parse(stream);

Thanks for help

joehw
Offline
Joined: 2004-12-15
Points: 0

Oh yes, that looks good.

Joe

joehw
Offline
Joined: 2004-12-15
Points: 0

If I understand correctly, that you wanted to convert a DOM Document into a string, you may get a transfomer and transform your document into a StreamResult wrapped around a StringWriter.

Joe

qwertyscar
Offline
Joined: 2008-04-16
Points: 0

thanks for the answer, is there also a way to convert a String to a Document?
thanks in advice