• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic