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

  • Home
  • SEARCH
  • 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 8113567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:52:13+00:00 2026-06-06T02:52:13+00:00

i am going through the code for xml parser, and i found this code,

  • 0

i am going through the code for xml parser, and i found this code,
but i want to save result data to a text file.

public class ReadXMLFile 
{

public static void main(String argv[]) 
{

  try {

    File fXmlFile = new File("test.xml");
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);
    doc.getDocumentElement().normalize();

    System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
    NodeList nList = doc.getElementsByTagName("test");
    System.out.println("-----------------------");

    for (int temp = 0; temp < nList.getLength(); temp++) {

       Node nNode = nList.item(temp);
       if (nNode.getNodeType() == Node.ELEMENT_NODE) {

          Element eElement = (Element) nNode;

          System.out.println("ID : " + getTagValue("id", eElement));
          System.out.println("Name : " + getTagValue("Name", eElement));
          System.out.println("AGE: " + getTagValue("age", eElement));

       }
    }
  } 
  catch (Exception e) 
  {
    e.printStackTrace();
  }
 }

 private static String getTagValue(String sTag, Element eElement) 
{
NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();

    Node nValue = (Node) nlList.item(0);

return nValue.getNodeValue();
}

}

how can i save the output to a text file ?

please suggest me regarding this…….

  • 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-06T02:52:14+00:00Added an answer on June 6, 2026 at 2:52 am

    Create a Writer to write to a file and replace System.out.println() with Writer.write().

    BufferedWriter writer = new BufferedWriter(new FileWriter(file));
    writer.write(s);
    writer.newLine();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm going through old code (2.0) and I came across this: object isReviewingValue
Just going through the sample Scala code on Scala website, but encountered an annoying
Please help me with this code - I am basically going through a book
I have written the following piece of code that reads through a given xml-file
I'm going through an XML file of articles and the journalist(s) that wrote them.
I'm going through another developer's code, which is shown below: [XmlElement(AdminRecipient)] public AdminRecipient[] AdminRecipientCollection
This code is supposed to read from an existing xml file, and write the
I am going through some code and at the beginning of the script we
While I'm going through Python code and seeing functions called, I notice things like
I was going through some code that I downloaded off the internet ( Got

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.