my dog learned polymorphism
The moose likes XML and Related Technologies and the fly likes XML Parsing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML Parsing " Watch "XML Parsing " New topic

XML Parsing

DhilipRaja Baskaran

Joined: Oct 08, 2008
Posts: 12
I do have problem while parsing a dollar symbol through my xml,basically when a dollar symbol comes in the xml which i convert to other xml using xslt ,the dollar symbol gets converted to a two character symbol (some symbol followed by dollar symbol like (A�))

I use jdk 1.4 and for parsing i use SAX API and JAXP ,The encoding of my input xml is UTF-8 and one used in xsl is the same .If I use the same input xml and same xsl with tool like altova the dollar symbol appears properly in the output

Can Anyone suggest a way out for this problem
Thanks in Advance
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Well, perhaps you aren't letting your parser use the document's encoding, but using a different encoding yourself. Or perhaps something else is wrong with the way you call the parser. Would you like to show us your code? Without it, we're just speculating.

Same with this "output" that you're displaying to. Is it the console? A Swing GUI? A web application? All of those things have their own challenges. Providing details always helps.
DhilipRaja Baskaran

Joined: Oct 08, 2008
Posts: 12
Hi ,

Follwing is the code for xml trnasformation ,the API used is jaxp and java version is 1.4

The input xml something looks like this

The xsl used for transformation looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
<xsl:template match="name">
<xsl:value-of select="."/>


The code for processing is
We call the below method for transforming the xml into other xml by supplying the Input xml,the name of xsl to use,and hashtable containing the value of parametr used in xsl

private String transform(String strInputXML, String strInputXSLFileName, Hashtable ht) throws Exception

String baosStr = null;
ByteArrayInputStream bais = null;
InputStreamReader inStreamReader = null;
BufferedReader reader = null;
ByteArrayOutputStream baos = null;

try {

TransformerFactory tFactory = TransformerFactory.newInstance();
String xsl = //The xsl file of which name is mentioned in the method signature loads though some code from here through singelton class(which loads xsl into memory when server is started) and the particular xsl

bais = new ByteArrayInputStream(xsl.getBytes());
inStreamReader = new InputStreamReader(bais);
reader = new BufferedReader(inStreamReader);

StreamSource source = new StreamSource(reader);
Transformer transformer = tFactory.newTransformer(source);

Enumeration enu = ht.keys();
while (enu.hasMoreElements()){
String strkey = (String) enu.nextElement();

// set parameters for transformation
transformer.setParameter(strkey, ht.get(strkey));

// perform the transformation
baos = new ByteArrayOutputStream();

transformer.transform(new StreamSource(new StringReader(strInputXML)), new StreamResult(baos));

baosStr = baos.toString();

}catch (Exception exception){

return baosStr;

After transformation the the output xml looks
<?xml version="1.0" encoding="UTF-8"?>


The problem is some symbol like A is getting added along with dollar
I agree. Here's the link:
subject: XML Parsing
jQuery in Action, 3rd edition