Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I convert the xml to a string?

 
Leo Tien
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a FAQ. You'll find several answers if you do a search on this forum for "xml string"...
 
Leo Tien
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cyril, I deleted the two posts for you. In the future, you can do it from the "edit/delete" view...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic