Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 14th, 2005, 04:15 AM
Registered User
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default append data to xml


I want to append data to xml file using java.
but it never be added to my users.xml file.
what was wrong with it?

this is the xml:

<?xml version="1.0" encoding="iso-8859-1"?>
    <user id="xxx" system="yyy" envlib="AAA" env="2" prefix="SPW" depot="NL2" proddiv="FD" lang="NED" />
    <user id="xxx" system="yyy" envlib="AAA" env="2" prefix="SPW" depot="NL2" proddiv="FD" lang="NED" />
    <user id="xxx" system="yyy" envlib="AAA" env="4" prefix="SPR" depot="ASD" proddiv="AV" lang="NED" />

this is my code :

String strFileName = getServletContext().getRealPath("/xml/user/users.xml");
   File file = new File(strFileName);
   Document doc = null;

       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
       DocumentBuilder db = dbf.newDocumentBuilder();
       doc = db.parse(file);
   catch(IOException e){

    Element root = doc.getDocumentElement();
    String nodeValue = root.getNodeName();

    Element newElement = doc.createElement("user");
    newElement.setAttributeNode(doc.createAttribute("i d"));
    newElement.setAttribute("id", "andhiez");
    newElement.setAttributeNode(doc.createAttribute("s ystem"));
    newElement.setAttribute("system", "andhiez");
    newElement.setAttributeNode(doc.createAttribute("e nvlib"));
    newElement.setAttribute("envlib", "andhiez");
    newElement.setAttributeNode(doc.createAttribute("e nv"));
    newElement.setAttribute("env", "andhiez");
    newElement.setAttributeNode(doc.createAttribute("p refix"));
    newElement.setAttribute("prefix", "andhiez");
    newElement.setAttributeNode(doc.createAttribute("d epot"));
    newElement.setAttribute("depot", "andhiez");
    newElement.setAttributeNode(doc.createAttribute("p roddiv"));
    newElement.setAttribute("proddiv", "andhiez");
    newElement.setAttributeNode(doc.createAttribute("l ang"));
    newElement.setAttribute("lang", "andhiez");

please help

Similar Threads
Thread Thread Starter Forum Replies Last Post
append a xml node from one file to another pravind XSLT 5 August 22nd, 2009 09:15 AM
append/insert data to xml file andhiez XML 5 April 18th, 2008 11:13 AM
append in xml file rapraj XML 3 October 11th, 2007 02:58 AM
Append Information to a XML file YoungLuke C# 2 July 26th, 2007 02:15 PM
What is the best method to append data? rdmapes PHP How-To 0 December 27th, 2006 01:06 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.