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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:32:54+00:00 2026-05-22T22:32:54+00:00

I generate the XML by reading the text form .txt file. But I got

  • 0

I generate the XML by reading the text form .txt file. But I got strange character results. I want to see my text in xml same as it is shown in .txt file.

here is my text from .txt file

žena
muškarac
devojčica
dečak
automobil
autobus
drvo
kuća
avion
mačka
pas
cvet

and here is my xml strange result.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<resources>
    <string name="0s0">žena</string>
    <string name="1s1">muškarac</string>
    <string name="2s2">devoj�ica</string>
    <string name="3s3">de�ak</string>
    <string name="4s4">automobil</string>
    <string name="5s5">autobus</string>
    <string name="6s6">drvo</string>
    <string name="7s7">kuća</string>
    <string name="8s8">avion</string>
    <string name="9s9">ma�ka</string>  

Here is my code.

          FileInputStream fstream = new FileInputStream("D:/12.txt"); // Path of input text file 
          BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
          String strLine;

          DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
          DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

          //root elements
          Document doc = docBuilder.newDocument();
          Element rootElement = doc.createElement("resources");
          doc.appendChild(rootElement);

          int i = 0;
          String attrName;
          //Read File Line By Line
          while ((strLine = br.readLine()) != null)   {

              attrName = i+"s"+i;
              i++;

              //staff elements
              Element string = doc.createElement("string");
              rootElement.appendChild(string);

              //set attribute to staff element
              Attr attr = doc.createAttribute("name");
              attr.setValue(attrName);
              string.setAttributeNode(attr);
              string.appendChild(doc.createTextNode(strLine));

          }
          //Close the input stream
          in.close();

          //write the content into xml file
          TransformerFactory transformerFactory = TransformerFactory.newInstance();
          Transformer transformer = transformerFactory.newTransformer();
          DOMSource source = new DOMSource(doc);
          StreamResult result =  new StreamResult(new File("D:\\italian.xml")); // Path of output text file
          transformer.transform(source, result);

          System.out.println("Done");        

I studied lot of posts in here but I could not get my desire solution. Just I want to see the same charecters / text in xml file as these are shown in .txt file.

  • 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-05-22T22:32:54+00:00Added an answer on May 22, 2026 at 10:32 pm

    You need to provide the correct Charset/Encoding when using the InputStreamReader. Try this:

    ... new InputStreamReader(in, "UTF-8");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to generate an XML file in C#. I want to write the
I am currently using SimpleXML to reading an xml file to generate my first
I've used boost serialization but this doesn't appear to allow me to generate xml
I want to generate some XML in a stored procedure based on data in
Im using Crytal report WPF Application to generate a report with xml file and
Is it possible to create a class dynamically by reading an xml file (
I have an XML file that I want to base some unit tests off
I have to generate XML in the below format <objects> <items> <item =delete> <searchfields>
I'm working in a .net application where we need to generate XML files on
At the office we are currently writing an application that will generate XML files

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.