File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes How can I convert the xml to a string? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How can I convert the xml to a string?" Watch "How can I convert the xml to a string?" New topic
Author

How can I convert the xml to a string?

Leo Tien
Ranch Hand

Joined: Sep 10, 2002
Posts: 156
Thanks.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
This is a FAQ. You'll find several answers if you do a search on this forum for "xml string"...


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Leo Tien
Ranch Hand

Joined: Sep 10, 2002
Posts: 156
Hi, Lasse:
I'v seen the topics from the search results, but none is I want.
I want use such as Xalan and XSL to convert a XML file to a String. e.g., a XML file have a tag named A and it's text value is a and have a tag named B and it's text value is b.
Now, I want to convert it to "ab" String, how should I do?
Thanks.
cyril vidal
Ranch Hand

Joined: Jul 02, 2003
Posts: 247
Sorry for the two precedent messages...
With XSLT, it is not difficult to get the values of all child elements:

As another solution, you may want to use SAX and just use the characters() method, like this:

A complete program to do this may be the following (just compile it and run it with xerces in your classpath):

Hoe this helps,
Cyril.


SCJP 1.4, SCWCD, SCBCD, IBM XML, IBM Websphere 285, IBM Websphere 287
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Cyril, I deleted the two posts for you. In the future, you can do it from the "edit/delete" view...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I convert the xml to a string?