如何在java中读取XML文件

时间:2011-09-06 12:41:00

标签: java xml

<?xml version="1.0"?> 
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" 
xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd" 
xmlns:db="http://www.milyn.org/xsd/smooks/db-routing-1.1.xsd" 
xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.2.xsd" 
xmlns:ds="http://www.milyn.org/xsd/smooks/datasource-1.1.xsd"> 

<ds:direct bindOnElement="#document" datasource="DB" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/dbase" username="root" password="praya123"   autoCommit="false" /> 
<db:executor executeOnElement="Invoice" datasource="DB" executeBefore="true"> 
<db:statement>SELECT * FROM custinfo</db:statement> 
<db:resultSet name="rs_custinfo" /> 
</db:executor> 
<db:executor executeOnElement="Invoice" datasource="DB" executeBefore="true"> 
<db:statement>select * from callRates</db:statement> 
<db:resultSet name="rs_callRates" /> 
</db:executor> 
<db:executor executeOnElement="Invoice" datasource="DB" executeBefore="true"> 
<db:statement>select * from InvoiceSummary</db:statement> 
<db:resultSet name="rs_InvoiceSummary" /> 
</db:executor> 
<db:executor executeOnElement="Invoice" datasource="DB" executeBefore="true"> 
<db:statement>select * from InvoiceDetail</db:statement> 
<db:resultSet name="rs_InvoiceDetail" /> 
</db:executor> 

<ftl:freemarker applyOnElement="Invoice"> 
<ftl:template> 

<!-- 
<#assign x=1> 
<#list 1..x as i> 

<DETAIL> 
<DT_INV_HDR1>${rs_custinfo[i].BillingAccNo}</DT_INV_HDR1> 
<DT_INV_HDR2>${rs_custinfo[i].CustNo}</DT_INV_HDR2> 
<DT_INV_HDR3>${rs_custinfo[i].InvoiceNo}</DT_INV_HDR3> 
<DT_INV_HDR4>${rs_custinfo[i].InvoiceDate}</DT_INV_HDR4> 
<DT_INV_HDR5>${rs_custinfo[i].PaymentDueDate}</DT_INV_HDR5> 
<DT_INV_HDR6/> 
<DT_INV_HDR7/> 
</DETAIL> 

</#list> 
--> 

</ftl:template> 
</ftl:freemarker> 
</smooks-resource-list>

如何用java获取数据?任何人都可以提供任何具体的方法吗?

2 个答案:

答案 0 :(得分:1)

DZone有一个非常好的,全面的refacrd,你应该阅读。

答案 1 :(得分:0)

请看这里:http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/

编辑:你会找到一个解析XML的类,它可能很有用。