• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

transforming xml from string source

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I use xalan to transform xml data to html
the xml data resides in a database the code is
something like:
String xmlData = new String();
//...
TransformerFactory tFactory = TransformerFactory.newInstance();
StringReader sr = new StringReader(xmlData);
Source xmlSource = new StreamSource(sr);
Source xslSource = new StreamSource(new URL("http://127.0.0.1:8080/aik/wordxml.xsl").openStream());
Transformer transformer = tFactory.newTransformer(xslSource);
transformer.transform(xmlSource, new StreamResult(out));

but the generated html's character encoding isn't what it's supposed to be
i guess the problem might be that i use StringReader instead of an InputStream, but is there a safe way to initialize an InputStream with
a String?
thanks in advance for any help
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gergely Dombi:
hi,
I use xalan to transform xml data to html
the xml data resides in a database the code is
something like:
String xmlData = new String();
//...
TransformerFactory tFactory = TransformerFactory.newInstance();
StringReader sr = new StringReader(xmlData);
Source xmlSource = new StreamSource(sr);
Source xslSource = new StreamSource(new URL("http://127.0.0.1:8080/aik/wordxml.xsl").openStream());
Transformer transformer = tFactory.newTransformer(xslSource);
transformer.transform(xmlSource, new StreamResult(out));

but the generated html's character encoding isn't what it's supposed to be
i guess the problem might be that i use StringReader instead of an InputStream, but is there a safe way to initialize an InputStream with
a String?
thanks in advance for any help


In my view,using stringreader doesn't affect much(with some exception)... but it could be better if you tell us what short character encoding problem you face in HTML, that could help to identify your exact problem location.
 
Gergely Dombi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Balaji,
we moved the xml data from the db to the file system so we could use an InputStream from the URL of the xml files
this solved the encoding problem
(the encoding is UTF-8)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic