• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Writing XML element

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic