|
-
December 28th, 2006, 07:17 AM
#1
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.
-
January 12th, 2007, 07:11 AM
#2
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.
-
January 18th, 2007, 05:49 PM
#3
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|