Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

java xml

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote the following code to read XML data to two String Arrays as follows :
//

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new File("aj.xml"));
NodeList namenode = document.getElementsByTagName("Name");
NodeList passnode = document.getElementsByTagName("Password");
String[] names = new String[250];
String[] passwords= new String[250];

for(int i=0; i<250; i++)
{
Element element = (Element)namenode.item(i);
names[i] = element.getTextContent();
Element element1 = (Element)passnode.item(i);
passwords[i] = element1.getTextContent();
}
//

The structure of my XML file was

//
<?xml version="1.0" encoding="UTF-8"?>
<Names>
<Data>
<Name>Ajeesh</Name>
<Password>me</Password>
</Data>
<Data>
<Name>Owen</Name>
<Password>oo</Password>
</Data>
<Data>
<Name>Rooney</Name>
<Password>rr</Password>
</Data>
<Data>
<Name>Beckham</Name>
<Password>bb</Password>
</Data>
</Names>
//

Now can anyone demostrate how to add, delete and edit any nodes.
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you try XML and Related Technologies , I write hundreds of lines of code but still have not begun on a real understanding of XML - that forum will probably give better luck.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic