• Post Reply Bookmark Topic Watch Topic
  • New Topic

java xml  RSS feed

 
Ajeesh Moidutty
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!