• Post Reply Bookmark Topic Watch Topic
  • New Topic

update xml string  RSS feed

 
Kishen Singh Punjabi
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a XML file and I am trying to update a particular attribute value in it as below and its working as expected



My XML File



But if I have the XML as string and I have to update the xml string, How do i save the updated XML ?



What should be the argument to the StreamResult ?? Is there any other way of doing it.?

I cannot use string replace functions as there a quite a few updates to be made. And I am able to add new nodes with the xml file. How to do it with xml string.


Thanks
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A StringWriter would be the natural choice if you want to get the result as a String.
 
Kishen Singh Punjabi
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf
I tried this :


But unfortunately I have output as


Thanks for the help
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the value of "stringWriter.toString()"? That's where I would expect the result of the transformation.
 
Kishen Singh Punjabi
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing this



Output is

How do I get rid of the xml tag that is added in the beginning of the output string.

Thanks
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is little point in passing in a StringWriter that you don't intend to use; I think your previous code was better.

That's not a tag, it's the XML prolog - why do you not want it? It's good to be explicit about the encoding.
 
Paul Clapham
Sheriff
Posts: 22834
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can set output properties on the Transformer object. They are the same properties which you can put in an <xsl:output> element in an XSL transformation. One of those might be what you are looking for.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!