File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Writing XML element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Writing XML element" Watch "Writing XML element" New topic
Author

Writing XML element

Sharon Cowling
Greenhorn

Joined: Feb 09, 2002
Posts: 18
Hi
I currently have a Java class that reads through an xml file searching for the input parameters - 1 is the element and 1 is the value, if the element is found and not the value the value needs to be inserted into the xml file, I can't figure out how to add the value, heres a code snippet:
Heres the bit i'm having trouble with:
if (e.getTagName().equals(id)) {
System.out.println("Did not find matching value node...adding new node now...");
Node c2 = document.createTextNode(value);
document.setNodeValue(value);
basically they enter in an id like <name> and a value such as "Bobs Company"
the code searches for the id entered and if there is no value that equals "Bobs company" it should be written to the xml file.
the full code is below. I am missing how to write an element to an already existing file as my above bit of code does not write anything!
a longer version of the code is below:
Please let me know if i need to provide more info.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Writing XML element
 
Similar Threads
xml processing problems
Efficient XML Parsing
Can anyone help?I still can't append records in xml...
XML DOM query
xml processing problems