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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:45:00+00:00 2026-06-03T06:45:00+00:00

Through a java program I am creating a xml of stock holders. The generated

  • 0

Through a java program I am creating a xml of stock holders. The generated xml would look like –

<?xml version="1.0" encoding="UTF-8" ?>
<urlset>
<url>
 <loc>FirstName-LastName/id/</loc>
</url>
</urlset>

There are some stock holders having special characters in there name e.g. A. Pitkänen. Now, when I see xml for this stock holders it looks like –

<?xml version="1.0" encoding="UTF-8" ?>
<urlset>
<url>
<loc>/A-Pitk寥n/ELS_1005091/</loc>
</url>
</urlset>

This is making the xml invalid. Why this is happening? The java program is –

FileWriter fstream = new FileWriter("c:\stock-holders.xml");
final BufferedWriter out = new BufferedWriter(fstream);

try {
    // Making Connection and query the stock holders to get the resultset

        String aId = "";
        String aFName = "";
        String aLName = "";

        out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
        out.write("<urlset>\n");

        while (rs.next()) {
            String url = "";

            aFName = rs.getString(2);
            if (StringUtils.isNotEmpty(aFName) ) {
                aFName = aFName.trim();
                url += aFName;
            }

            aLName = rs.getString(3);
            if (StringUtils.isNotEmpty(aLName)) {
                aLName = aLName.trim();
                url += "-" + aFName;

            }

            aId = rs.getString(1);
            if (StringUtils.isNotEmpty(aId)) {
                aId = aId.trim();
                url += "/" + aId + "/";
            }

            out.write("<url>\n");
            out.write("<loc>" + url + "</loc>\n");
            out.write("</url>\n");
            out.flush();
        }
        out.write("</urlset>");
        out.close();
    }
  • 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-03T06:45:02+00:00Added an answer on June 3, 2026 at 6:45 am

    Sicne your XML file is supposed to be written in UTF-8 encoding, you need to configure your Writers to use that encoding rather than the system default one:

    FileOutputStream fstream = new FileOutputStream("c:\stock-holders.xml"); 
    OutputStreamWriter writer = new OutputStreamWriter(fstream, "UTF-8");
    final BufferedWriter out = new BufferedWriter(writer); 
    

    Note that use of FileWriter is not recommended for this very reason – it cannot be configured to use encoding other than the default one.

    Also, perhaps it would be better to use some existing API for constructing XML files (such as DOM or StAX) rather than do it by string concatenation. For example, your solution doesn’t take into account that your data may contain characters that are illegal in XML and should be escaped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create registry key through java program to add the jar file
I want to increase my CPU usage through a java program, albeit in a
Say suppose I am running a java program through command line. And this program
I have a Java program in which an action is initiated which loops through
I am generating JavaScript pages through Java code like: FileOutputStream fs=new FileOutputStream(C:\\Documents and Settings\\prajakta\\Desktop\\searcheng.html);
I want to execute dos based external command through java program if there there
I'm using JNI to access a native C file through my java program. I've
I'm making a C Assessment Program through Java, which has a bunch of programming
How to access the another system mysql database through java program?Am using the following
Okay so I am pretty much doing a crash course through creating a java

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.