• 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
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • 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.
 
Everyone is a villain in someone else's story. Especially this devious tiny ad:
Master Gardener Program
https://coderanch.com/t/771761/Master-Gardener-Program
reply
    Bookmark Topic Watch Topic
  • New Topic