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 8928885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:33:01+00:00 2026-06-15T08:33:01+00:00

I am taking some strings from a .xlsx file (the strings are simple characters).

  • 0

I am taking some strings from a .xlsx file (the strings are simple characters). Then I am trying to put those strings in an .xml file. But unfortunately, when I put those strings in the ‘createElement(StringVariableHere)’ method, I get the following error: “org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.”

I get the string values in this way:

switch (tempCell.getCellType()) {
    case Cell.CELL_TYPE_STRING:
    String tempColValue = tempCell.getStringCellValue();
}

And this is the line where i try to add my string values and it gives me the error.

Element titleChild = doc.createElement(StringVariableHere);

I even tried to clean the string using the following method i found online:

public String stripNonValidXMLCharacters(String in) {
    StringBuffer out = new StringBuffer(); // Used to hold the output.
    char current; // Used to reference the current character.

    if (in == null || ("".equals(in))) return ""; // vacancy test.
    for (int i = 0; i < in.length(); i++) {
        current = in.charAt(i); // NOTE: No IndexOutOfBoundsException caught here; it should not happen.
        if ((current == 0x9) ||
            (current == 0xA) ||
            (current == 0xD) ||
            ((current >= 0x20) && (current <= 0xD7FF)) ||
            ((current >= 0xE000) && (current <= 0xFFFD)) ||
            ((current >= 0x10000) && (current <= 0x10FFFF)))
            out.append(current);
    }
    return out.toString();
}

Also i am using the following to check if it is valid or not, and when i add my string it returns false:

XMLChar.isValidName(StringVariableHere)

Thank you all so much for your time. Stefanos.

  • 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-15T08:33:03+00:00Added an answer on June 15, 2026 at 8:33 am

    did you try looking at the string you get in java? printing it to the console or such?

    It reminds me of similar issues i had parsing office document. The parser (apache POI) was sometimes giving unicode invalid characters which were breaking the xml (one example was with line breaks).

    I don’t know what parser you are using but you might have to clean your string before trying to fill your xml.

    Edit after the added details.

    What kind of xml are you trying to write? can you provide an example?
    doc.createElement(StringVariableHere) means you try to create an element named StringVariableHere. I.E.

    <StringVariableHere>there could be something here</StringVariableHere>
    

    not

    <aRandomTag>StringVariableHere</aRandomTag>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm taking fields from a webform and trying to save the inputs to the
I have a simple monitoring application that is getting some values from PerfMon counters.
Thanks for taking some time to help me out. Using: Microsoft Visual C# 2010
I've got a struts2 action that responds to an AJAX request by taking some
I am loading url into webview: WebView webview=(WebView)findViewById(R.id.webview); webview.loadUrl(url); It's taking some time to
I'm a bit of a NHibernate newbie and Im taking on some code written
So I had a thread that was taking care of some network stuff for
I made some changes to an open source project without taking time to create
I'm taking a look at some random Icecast playlists (available here: http://dir.xiph.org/index.php ) and
This problem is taking me too long to fix I could use some guidance

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.