CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2005
    Posts
    53

    Writing to a XML file using java

    I try to write some elements in an existing xml file.

    Original XML file is
    <Config>
    <host type="Array">
    </host>
    </Config>

    I want to insert node inside host tag like
    Code:
    <Config>
       <host type="Array">	
           <element>
                <name>ServerName1</name>
           </element>	
           <element>
               <name>ServerName2</name>
           </element>
       </host>
    </Config>
    I tried using createElement() method, but i'm getting xml file as

    <Config>
    <host type="Array">
    </host>
    <name>ServerName</name>
    </Config>

    How to get the expected XML using java?

    Can anyone guide me?

    -haifriends.

  2. #2
    Join Date
    May 2003
    Location
    Germany
    Posts
    936

    Re: Writing to a XML file using java

    I do not used Java for a long time but in general should trying the following steps:

    1. Load the existent XML file with a DOM parser.
    2. Navigate to the node where you want to add a child node.
    3. Create a new Node with the value you want to store.
    4. Add the new node to the node selected at 2.)
    5. Save your XML to file.

    In your case the creation of the XML element works but you add the node to the wrong parent. Select the "host" element and insert the node there.
    Useful or not? Rate my posting. Thanks.

  3. #3
    Join Date
    Mar 2000
    Location
    Vancouver, BC, Canada
    Posts
    278

    Re: Writing to a XML file using java

    can you post the section of your code that is appending the child node to the list?
    David Meikle
    Quantum Unit Solutions, LLC
    www.quantumunit.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured