Reputation: 45
I have xml file as below
<dashboard DASHBOARD_ID="1" DASHBOARD_IMAGE="" DASHBOARD_NAME="TestDashboard">
<linkedpages>
<pages page_id=1212 pagename=""/>
<report reportid=212 reportname=""/>
</linkedpages>
my need is that I should import these tag attribute velues int o respective table say page table, report table, dashborad table and so on.
I am get the elements and their attributes by
String attribute = child.getAttribute("report_id");
but I need to write n number of such line, and its not generic, i can have variable length of attributes. So i need to be able to read all attributes of each tag.
How can this be done Please help, Any idea of doing this is appreciated. Thank You
Upvotes: 0
Views: 69
Reputation: 10707
Try this method : getAttributes()
And an example:
List<String> attributNames = new ArrayList<String>();
if(child.getAttributes() != null){
for (int i = 0; i < child.getAttributes().getLength(); i++) {
attributNames.add(child.getAttributes().item(i).getNodeName());
}
}
Upvotes: 1
Reputation: 7207
String[] attributes = new String[child.getAttributes().getLength()];
for (int i = 0; i < attributes.length; i++) {
attributes[i] = child.getAttributes().item(i).getNodeValue();
}
Upvotes: 1