TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sris Sri
NA
6
590
i am trying to create bean object for parsed xml values
Sep 20 2017 10:00 AM
my xml
<?xml version="1.0" encoding="UTF-8"?>
<Details>
<user>
<user_name>Ravi</user_name>
<pass_word>Babu</pass_word>
<first_Name>Ravi</first_Name>
<last_Name>Babu</last_Name>
<email_address>
[email protected]
</email_address>
</user>
</Details>
my pojo
public class Pojo
{
private String first_Name;
private String last_Name;
private String email_address;
private String user_name;
private String pass_word;
#setter and Gettere
}
my main class
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();
}
}
}
Please help i need this values to pojo so that i can add this values to sql
Reply
Answers (
0
)
How to cache unsaved form data either Spring or Hibernate.
how to call a method of another class (TimerSessionBean)