从数据库中查询数据然后生成xml文件,如何是表中的空字段值在xml文件中节点成对出现?
Documentdoc=DocumentHelper.createDocument();ElementrootEle=doc.addElement("package");...
Document doc = DocumentHelper.createDocument();
Element rootEle = doc.addElement("package");
Element headEle = rootEle.addElement("packagehead");
Element dwdmEle = headEle.addElement("bdzd");
dwdmEle.setText("gmsfhm,xm,xb,csrq,mz");
////////////////////////////////
Element dataEle = rootEle.addElement("data");
try
{
pqry.clearSql();
pqry.addSQL(" select pid,name,gender,to_char(dob,'yyyy-MM-dd') as csrq,nation from v_tp_huji_static ");
pqry.openSQL();
int no=0;
while (pqry.getRowSet().next()){
no=no+1;
Element recordEle = dataEle.addElement("record");
recordEle.addAttribute("no", Integer.toString(no));
Element gmsfhmEle = recordEle.addElement("gmsfhm");
gmsfhmEle.setText(myreq.formatStr(pqry.getRowSet().getString("pid")));
Element nameEle = recordEle.addElement("xm");
nameEle.setText(myreq.formatStr(pqry.getRowSet().getString("name")));
Element xbEle = recordEle.addElement("xb");
xbEle.setText(myreq.formatStr(pqry.getRowSet().getString("gender")));
Element csrqEle = recordEle.addElement("csrq");
csrqEle.setText(myreq.formatStr(pqry.getRowSet().getString("csrq")));
Element mzEle = recordEle.addElement("mz");
mzEle.setText(myreq.formatStr(pqry.getRowSet().getString("nation")));
}
这是部分代码,就是生成节点的地方,如果字段值为空xml文件就会只显示一个节点不是成对的,求各位帮忙解决 展开
Element rootEle = doc.addElement("package");
Element headEle = rootEle.addElement("packagehead");
Element dwdmEle = headEle.addElement("bdzd");
dwdmEle.setText("gmsfhm,xm,xb,csrq,mz");
////////////////////////////////
Element dataEle = rootEle.addElement("data");
try
{
pqry.clearSql();
pqry.addSQL(" select pid,name,gender,to_char(dob,'yyyy-MM-dd') as csrq,nation from v_tp_huji_static ");
pqry.openSQL();
int no=0;
while (pqry.getRowSet().next()){
no=no+1;
Element recordEle = dataEle.addElement("record");
recordEle.addAttribute("no", Integer.toString(no));
Element gmsfhmEle = recordEle.addElement("gmsfhm");
gmsfhmEle.setText(myreq.formatStr(pqry.getRowSet().getString("pid")));
Element nameEle = recordEle.addElement("xm");
nameEle.setText(myreq.formatStr(pqry.getRowSet().getString("name")));
Element xbEle = recordEle.addElement("xb");
xbEle.setText(myreq.formatStr(pqry.getRowSet().getString("gender")));
Element csrqEle = recordEle.addElement("csrq");
csrqEle.setText(myreq.formatStr(pqry.getRowSet().getString("csrq")));
Element mzEle = recordEle.addElement("mz");
mzEle.setText(myreq.formatStr(pqry.getRowSet().getString("nation")));
}
这是部分代码,就是生成节点的地方,如果字段值为空xml文件就会只显示一个节点不是成对的,求各位帮忙解决 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询