aspose file tools*
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
Author

XML Parsing

DhilipRaja Baskaran
Greenhorn

Joined: Oct 08, 2008
Posts: 12
Hi,
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
Bartender

Joined: Oct 14, 2005
Posts: 18672
    
    8

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
Greenhorn

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
<name>�</name>

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

</xsl:template>
</xsl:stylesheet>

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"?>

<name>A�</name>

The problem is some symbol like A is getting added along with dollar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML Parsing