<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <employee name = "abc" empId = "100" location = "goa" dept = "IT" /> <facilities transport="Y" mealcard = "" driver = "Y"/> <reportees manager = "XXX" lead = "XXX" VP = "XXX"/> <employee name = "XYZ" empId = "101" location = "mombai" dept = "IT" /> <facilities transport="Y" mealcard = "" driver = "Y"/> <reportees manager = "XXX" lead = "XXX" VP = "XXX"/> <employee name = "PQA" empId = "102" location = "delhi" dept = "IT" /> <facilities transport="Y" mealcard = "" driver = "Y"/> <reportees manager = "XXX" lead = "XXX" VP = "XXX"/>
above is my XML. I’ve to validate the same. I’m using DBUnit to compare the same XML with other XML (other XML has the same content but generated from different source). While creating dataset I’m getting “org.dbunit.database.AmbiguousTableNameException”.
I’ve SQL query for every XML tag. E.g. For employee tag I’m querying on empID. for facilities I’m querying on mealCard etc etc. I’m looping through the XML tags. first iteration goes fine without error. I’m using QueryDataSet.addTable(table_name ,query) to add tables i.e xml tags. But when next iteration comes and I’m trying to add employee tag again I’m getting the above stated error.
Advertisement
Answer
I resolved this issue. I’ll tell you how. In dataset for repeating tags I just added random numbers e.g. in my above XML employee is repeating tag hence I added employee_123 for the first instance in dataset for next instance I added employee_098 this is how I manage to get rid of AmbigiousTableNameException. Later I used RegEx to remove the “_[randomNumber]” appended to employee tag. The code is running successful.