• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

appending node to xml file

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i append node to existing xml file. if somebody can give code that will be helpful
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi amit,
Here is the sample code to achieve your task..
Document document=new SAXReader().read("c:/student.xml");
Element students=document.getRootElement() ;
Element student=students.addElement("student");
Element id=student.addElement("id")
.addText("2");
Element name=student.addElement("name")
.addText("name2");
Element city=student.addElement("city")
.addText("city2");
FileOutputStream f1=new FileOutputStream("c:/student.xml");
XMLWriter writer=new XMLWriter(f1);
writer.write(document);
write.flush();
f1.close();
------------
// student.xml
<?xml version="1.0" encoding="UTF-8" ?>
<students>
<student>
<id>1</id>
<name>name1</name>
<city>city1</city>
</student>
<student>
<id>2</id>
<name>name2</name>
<city>city2</city>
</student>
</students>
Hope i fulfilled your request...
Best Regards,
Paramaguru
 
Paramagurusamy Balasubramanian
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi amit,
Here is the sample code to achieve your task..
Document document=new SAXReader().read("c:/student.xml");
Element students=document.getRootElement() ;
Element student=students.addElement("student");
Element id=student.addElement("id")
.addText("2");
Element name=student.addElement("name")
.addText("name2");
Element city=student.addElement("city")
.addText("city2");
FileOutputStream f1=new FileOutputStream("c:/student.xml");
XMLWriter writer=new XMLWriter(f1);
writer.write(document);
write.flush();
f1.close();
------------
// student.xml
<?xml version="1.0" encoding="UTF-8" ?>
<students>
<student>
<id>1</id>
<name>name1</name>
<city>city1</city>
</student>
<student>
<id>2</id>
<name>name2</name>
<city>city2</city>
</student>
</students>
Hope i fulfilled your request...
Best Regards,
Paramaguru
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dim Node as xmlNode
Dim Doc As New XmlDocument()
Node = Doc.DocumentElement
Dim elem As XmlElement = Doc.CreateElement("Node Name You Want To creat")
elem.InnerText = txtName.Text
Node.InsertAfter(elem, Node.FirstChild)
Doc.Save(path)
 
What's that smell? Hey, sniff this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic