Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8497913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:15:37+00:00 2026-06-11T00:15:37+00:00

When I am parsing the string to org.w3c.dom.Element I am getting following exception. org.xml.sax.SAXParseException;

  • 0

When I am parsing the string to org.w3c.dom.Element I am getting following exception.

org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 245; Invalid byte 3 of 3-byte UTF-8 sequence.

Code that I have used to convert string to element is:

public Element convertStringToDoc(String xmlString) throws Exception{
    org.w3c.dom.Document doc;
    try {
        java.io.InputStream sbis = new java.io.StringBufferInputStream(xmlString);
        javax.xml.parsers.DocumentBuilderFactory b = javax.xml.parsers.DocumentBuilderFactory.newInstance();
        b.setNamespaceAware(false);
        doc = null;
        javax.xml.parsers.DocumentBuilder db = null;
        db = b.newDocumentBuilder();
        doc = db.parse(sbis);
        org.w3c.dom.Element e = doc.getDocumentElement();
        return e;
    } catch (Exception e1) {
        throw e1;

}
}

and my input string is:

<?xml version="1.0" encoding="UTF-8"?>
<a id="ctl00_RSContent1_ResultsList_ctl00_ProductTitleLink" href="../Product/the_western_european_wear_tear_parts_market_201115?productid=TD00033-006">The Western European Wear &amp; Tear Parts Market, 2011–15</a>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:15:38+00:00Added an answer on June 11, 2026 at 12:15 am

    In my opinion the java String class is not UTF-8 encoded. It seems the “–” sequence has in java string unicode a byte coding that is not allowed in UTF-8. Change your code like this …

    ...
    byte[] utf8Bytes=xmlString.getBytes("UTF-8");
    java.io.InputStream sbis = new java.io.ByteArrayInputStream(utf8Bytes);
    javax.xml.parsers.DocumentBuilderFactory b = javax.xml.parsers.DocumentBuilderFactory.newInstance();
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a lot of XML parsing/transformation using the org.w3c.dom classes. A Document
Parsing the string message seems bad. Or was this exception not meant to be
I'm parsing a XML string into XMLDocument object. I want to search for a
I got a string from parsing a XML file which looks like this: Fri,
Hi I am currently having a problem with parsing an Xml string without any
I'm parsing large XML document using pull parser ( org.xmlpull.v1.XmlPullParser ). When I reach
We are parsing an XML file with the SAX parser. Is it possible to
I'm new to xml parsing, I am trying to parse the following xml file
I have a spring-integration transformer that accepts a org.w3c.dom.Document and returns a domain object.
I'm parsing an XML string and have a memory leak. I know this code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.