下面是我的代码,我正在尝试生成一个 我有一个Excel Spradsheet,我正在尝试读取数据并生成XML,我正在努力创建适当的循环方法来生成XML文件,感谢任何帮助
ObjectFactory fct = new ObjectFactory();
ImportParams imp = fct.createImportParams();
FolderMaps fmaps = fct.createFolderMaps();
FolderMap fmap = null;
List<object> objs=new ArrayList<object>();
int numOfProduct = data.size();
System.out.println("Number of lines " + numOfProduct);
for (int i = 0; i < numOfProduct; i++){
fmap =fct.createFolderMap();
int index = 0;
for(String s: data.get(i)) {
String headerString = data.get(i).get(index);
System.out.println("For index " + index + "and value of row "+i+ " header string is " + headerString);
fmap.setSourceProject (data.get(i).get(0));
fmap.setSourceFolderPath (data.get(i).get(1));
Object ob = fct.createObject();
ob.setName(data.get(i).get(6));
ObjectList obl = fct.createObjectList();
obl.setSelect("all");
obl.setResolution("replace");
obl.setType(data.get(i).get(5));
obl.getObject().add(ob);
fmap.getObjectList().add(obl);
index++;
}
}
fmaps.getFolderMap().add(fmap);
imp.setFolderMaps(fmaps);
System.out.println("Size is " + imp.getFolderMaps().getFolderMap().size());
JAXBContext ctx = null;
System.out.println("Writing JAXB objects");
try {
ctx = JAXBContext.newInstance("com.au");
System.out.println("Inside JAXB");
Marshaller marshaller = ctx.createMarshaller();
System.out.println("Marshal Started");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(imp, System.out);
System.out.println("Marshal Completed");
marshaller.marshal(imp, new File ("C:\\Users\\prudra\\Desktop\\eclipse_workspace_64\\abcjaxb.xml"));
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
以下输出
Writing to text file is completed...
Number of lines 7
For index 0and value of row 0 header string is Unknown
For index 1and value of row 0 header string is test
For index 2and value of row 0 header string is Unknown
For index 3and value of row 0 header string is import
For index 4and value of row 0 header string is truth
For index 5and value of row 0 header string is Application
For index 6and value of row 0 header string is all
For index 7and value of row 0 header string is replace
For index 8and value of row 0 header string is App_Hive_Incremental_Simple
For index 0and value of row 1 header string is Unknown
For index 1and value of row 1 header string is test
For index 2and value of row 1 header string is Unknown
For index 3and value of row 1 header string is import
For index 4and value of row 1 header string is truth
For index 5and value of row 1 header string is Workflow
For index 6and value of row 1 header string is all
For index 7and value of row 1 header string is replace
For index 8and value of row 1 header string is wf_Hive_Incremental_Simple
For index 0and value of row 2 header string is Unknown
For index 1and value of row 2 header string is test
For index 2and value of row 2 header string is Unknown
For index 3and value of row 2 header string is import
For index 4and value of row 2 header string is truth
For index 5and value of row 2 header string is mapping
For index 6and value of row 2 header string is m_Get_Max_Loaded_Value
For index 0and value of row 3 header string is Unknown
For index 1and value of row 3 header string is test
For index 2and value of row 3 header string is Unknown
For index 3and value of row 3 header string is import
For index 4and value of row 3 header string is truth
For index 5and value of row 3 header string is mapping
For index 6and value of row 3 header string is m_Hive_Incremental_Read
For index 0and value of row 4 header string is Unknown
For index 1and value of row 4 header string is test
For index 2and value of row 4 header string is Unknown
For index 3and value of row 4 header string is import
For index 4and value of row 4 header string is truth
For index 5and value of row 4 header string is Relational Data Object
For index 6and value of row 4 header string is student_data_target
For index 0and value of row 5 header string is Unknown
For index 1and value of row 5 header string is test
For index 2and value of row 5 header string is Unknown
For index 3and value of row 5 header string is import
For index 4and value of row 5 header string is truth
For index 5and value of row 5 header string is Flat File Data Object
For index 6and value of row 5 header string is studentdata
For index 0and value of row 6 header string is Unknown
For index 1and value of row 6 header string is test
For index 2and value of row 6 header string is Unknown
For index 3and value of row 6 header string is import
For index 4and value of row 6 header string is truth
For index 5and value of row 6 header string is Flat File Data Object
For index 6and value of row 6 header string is ff_temp
Size is 1
Writing JAXB objects
Inside JAXB
Marshal Started
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<importParams xmlns="http://www.informatica.com/oie/importControl/9">
<folderMaps>
<folderMap sourceProject="Unknown" sourceFolderPath="test">
<objectList type="Flat File Data Object" select="all" resolution="replace">
<object name="ff_temp"/>
</objectList>
<objectList type="Flat File Data Object" select="all" resolution="replace">
<object name="ff_temp"/>
</objectList>
<objectList type="Flat File Data Object" select="all" resolution="replace">
<object name="ff_temp"/>
</objectList>
<objectList type="Flat File Data Object" select="all" resolution="replace">
<object name="ff_temp"/>
</objectList>
<objectList type="Flat File Data Object" select="all" resolution="replace">
<object name="ff_temp"/>
</objectList>
<objectList type="Flat File Data Object" select="all" resolution="replace">
<object name="ff_temp"/>
</objectList>
<objectList type="Flat File Data Object" select="all" resolution="replace">
<object name="ff_temp"/>
</objectList>
</folderMap>
</folderMaps>
</importParams>
Marshal Completed
我们可以看到XML仅从excel的最后一行生成元素,而附件是excel输入
下面是我要实现的输出
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<importParams xmlns="http://www.informatica.com/oie/importControl/9">
<folderMaps>
<folderMap sourceProject="Unknown" sourceFolderPath="test">
<objectList type="Application" select="all" resolution="replace">
<object name="App_Hive_Incremental"/>
</objectList>
<objectList type="Workflow" select="all" resolution="replace">
<object name="wf_hive_incremental"/>
</objectList>
<objectList type="mapping" select="all" resolution="replace">
<object name="m_Get_Max_Loaded_Value"/>
</objectList>
<objectList type="mapping" select="all" resolution="replace">
<object name="m_Hive_Incremental_Read"/>
</objectList>
<objectList type="Relational Data Object" select="all" resolution="replace">
<object name="student_data_target"/>
</objectList>
<objectList type="Flat File Data Object" select="all" resolution="replace">
<object name="Student_Data"/>
</objectList>
<objectList type="Flat File Data Object" select="all" resolution="replace">
<object name="ff_temp"/>
</objectList>
</folderMap>
</folderMaps>
</importParams>