posted 17 years ago
I have an Xml file I have to parse this XML.While parsing i faced an issue.
for parsing i am using this code
NodeList nodes1 = xmlDoc.getElementsByTagName("table");
for (int i=0;i< nodes1.getLength(); i++) {
Element titleElem =(Element)nodes1.item(i);
Attr type = titleElem.getAttributeNode("name");
Node childNode = type.getFirstChild();
System.out.println("table Name is: " + childNode.getNodeValue());
System.out.println("table NodeName is: " + childNode.ELEMENT_NODE);
NodeList nodes2 = xmlDoc.getElementsByTagName("field");
for (int j=0;j< nodes2.getLength();j++) {
Element titleElem1 =(Element)nodes2.item(j);
Attr type3 = titleElem1.getAttributeNode("Name");
Node childNode2 = type3.getFirstChild();
System.out.println("field Name is: " + childNode2.getNodeValue());
}
}
Then i got this results
table Name is: acc_credit_cnfg
table NodeName is: 1
field Name is: str_store_id
field Name is: str_merchant_id
field Name is: str_fnam
field Name is: str_lnam
table Name is: acc_gc_pymt
table NodeName is: 1
field Name is: str_store_id
field Name is: str_merchant_id
field Name is: str_fnam
field Name is: str_lnam
But this is wrong ...Bcoz i have to get the result like this.....
table Name is: acc_credit_cnfg
table NodeName is: 1
field Name is: str_store_id
field Name is: str_merchant_id
table Name is: acc_gc_pymt
table NodeName is: 1
field Name is: str_fnam
field Name is: str_lnam...For that i tried too many ways but all are fail, Any One pls help me to sove this issue.
Sample XML File is Attched With this
<?xml version="1.0" encoding="ISO-8859-1"?>
<parameters>
<param type="Input">
<table name ="acc_credit_cnfg">
<fields>
<field Name ="str_store_id" type ="varchar" enable ="Yes" key ="Yes" aliasName ="Store Id"/>
<field Name ="str_merchant_id" type ="varchar" enable ="Yes" key ="Yes" aliasName ="Merchant Id"/>
</fields>
</table>
<table name ="acc_gc_pymt">
<fields>
<field Name ="str_fnam" type ="varchar" enable ="Yes" key ="Yes" aliasName ="First Name"/>
<field Name ="str_lnam" type ="varchar" enable ="Yes" key ="Yes" aliasName ="Last Name"/>
<fields>
</table>
</param>
</parameters>
[ June 11, 2006: Message edited by: Bear Bibeault ]