Advertisement

02.18.2005 at 04:23AM PST, ID: 21319946
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

Handling of special characters to avoid UTFDataFormatException

Asked by jas123 in Extensible Markup Language (XML), Font Creator

Tags: , , ,

Hi,

On my weblogic server 8.1, I have a small piece of code which reads xml data and generates reports in PDF format.

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import org.xml.sax.InputSource;

//HERE the xslTransform is passed as a StringBuffer of size 512
public String transform (String xmlData, String xslTransform) throws Exception
{
      String outputXML = null;
      
      //1. first convert the input xml to a source
      Source dataSource = createSource(xmlData);      
      
      //2. convert this xsl too to a Source
      Source xslSource  = createSource(xslTransform);
            
      //3. convert the xsl to a Transformer
      TransformerFactory factory = TransformerFactory.newInstance();
      Transformer transformer = factory.newTransformer(xslSource);
      
      //4. create a output result for the output of the transform
      StreamResult result = createResult();
      
      //5. transform
      try
      {
            transformer.transform(dataSource,result);
      }
      catch(Exception e)
      {
            e.printStackTrace(); // THE ERROR PRINTED HERE is java.lang.OutOfMemoryError
      }
      
      //6. get the String the stream result
      //the following works because toString is overridden for ByateArrayOutputStream
      
      outputXML = result.getOutputStream().toString();
      
      //7. return the string result
      return outputXML;

}

private Source createSource(String xml)
{
      //1. create a byte array
      byte[] array = xml.getBytes();
      
      //2. create a inputstrem for this array
      ByteArrayInputStream xmlStream = new  ByteArrayInputStream(array);
            
      //3. now create a SAXSource from this stream
      Source xmlSource = new SAXSource(new InputSource(xmlStream));            

      return xmlSource;
}
      
private StreamResult createResult()
{
      ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
      return new StreamResult(baos);
}

But if the xml size is too big, I get java.lang.OutOfMemoryError.

Can you please give me a solution for this?

Also, even if my xml is small and it contains some special characters like “Threshold is ú3,000”

It gives me the following exception:

javax.xml.transform.TransformerException: java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence.

How to handle these special charaters?

Start Free Trial
[+][-]02.18.2005 at 05:44AM PST, ID: 13345367

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.20.2005 at 11:31PM PST, ID: 13360698

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.21.2005 at 12:27AM PST, ID: 13360889

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.21.2005 at 02:22AM PST, ID: 13361434

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.21.2005 at 03:41AM PST, ID: 13361873

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.21.2005 at 07:15AM PST, ID: 13363353

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.21.2005 at 07:16AM PST, ID: 13363362

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.23.2005 at 01:33AM PST, ID: 13380416

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.23.2005 at 01:39AM PST, ID: 13380456

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Extensible Markup Language (XML), Font Creator
Tags: utfdataformatexception, byte, 1, invalid
Sign Up Now!
Solution Provided By: ramazanyich
Participating Experts: 1
Solution Grade: A
 
 
[+][-]02.23.2005 at 02:43PM PST, ID: 13388038

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.21.2005 at 01:08PM PDT, ID: 14720183

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]12.26.2005 at 03:52PM PST, ID: 15552733

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]12.31.2005 at 07:26AM PST, ID: 15583608

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43