public class Pojo
{
private String first_Name;
private String last_Name;
private String email_address;
private String user_name;
private String pass_word;
public class xmlDom {
public static void main(String[] args) {
final List<Pojo> pojos = new LinkedList<Pojo>();
DocumentBuilderFactory Factory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder Builder = Factory.newDocumentBuilder();
Document doc=Builder.parse("DataBase.xml");
NodeList personList=doc.getElementsByTagName("user");
for(int i=0;i<personList.getLength();i++)
{
Node p=personList.item(i);
if(p.getNodeType()==Node.ELEMENT_NODE)
{
Element User=(Element) p;
NodeList nameList=User.getChildNodes();
for(int j=0;j<nameList.getLength();j++)
{
Node n = nameList.item(j);
if(n.getNodeType()==Node.ELEMENT_NODE)
{
Element name=(Element) n;
Pojo pojo = new Pojo();
pojo.setUser_name(name.getElementsByTagName("user_name").item(0).getTextContent());
pojo.setPass_word(name.getElementsByTagName("pass_word").item(0).getTextContent());
pojo.setFirst_Name(name.getElementsByTagName("first_Name").item(0).getTextContent());
pojo.setLast_Name(name.getElementsByTagName("last_Name").item(0).getTextContent());
pojo.setEmail_address(name.getElementsByTagName("email_address").item(0).getTextContent());
pojos.add(pojo);
}
}
}
}
for(final Pojo pojo : pojos) {
System.out.println(pojo.getFirst_Name());
}
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}