给个例子你, 自己去套用就行给你
<xml version="10" encoding="utf-8"><Accounts>
<Account type="type1">
<code>100001</code>
<pass>123</pass>
<name>李四</name>
<money>100000000</money>
</Account>
<Account type="type2">
<code>100002</code>
<pass>123</pass>
<name>张三</name>
<money>100000</money>
</Account>
</Accounts>
java代码解析:
import javaio;/
xml文件解析
@author young
/
import javaxxmlparsersDocumentBuilder;
import javaxxmlparsersDocumentBuilderFactory;
import orgw3cdomDocument;
import orgw3cdomElement;
import orgw3cdomNode;
import orgw3cdomNodeList;
public class XmlExam {
public static void main(String args[]) {
Element element = null;
// 可以使用绝对路劲
File f = new File("xmlxml");
// documentBuilder为抽象不能直接实例化(将XML文件转换为DOM文件)
DocumentBuilder db = null;
DocumentBuilderFactory dbf = null;
try {
// 返回documentBuilderFactory对象
dbf = DocumentBuilderFactorynewInstance();
// 返回db对象用documentBuilderFatory对象获得返回documentBuildr对象
db = dbfnewDocumentBuilder();
// 得到一个DOM并返回给document对象
Document dt = dbparse(f);
// 得到一个elment根元素
element = dtgetDocumentElement();
// 获得根节点
Systemoutprintln("根元素:" + elementgetNodeName());
// 获得根元素下的子节点
NodeList childNodes = elementgetChildNodes();
// 遍历这些子节点
for (int i = 0; i < childNodesgetLength(); i++) {
// 获得每个对应位置i的结点
Node node1 = childNodesitem(i);
if ("Account"equals(node1getNodeName())) {
// 如果节点的名称为"Account",则输出Account元素属性type
Systemoutprintln("\r\n找到一篇账号 所属区域: "
+ node1getAttributes()getNamedItem("type")
getNodeValue() + " ");
// 获得<Accounts>下的节点
NodeList nodeDetail = node1getChildNodes();
// 遍历<Accounts>下的节点
for (int j = 0; j < nodeDetailgetLength(); j++) {
// 获得<Accounts>元素每一个节点
Node detail = nodeDetailitem(j);
if ("code"equals(detailgetNodeName())) // 输出code
Systemout
println("卡号: " + detailgetTextContent());
else if ("pass"equals(detailgetNodeName())) // 输出pass
Systemout
println("密码: " + detailgetTextContent());
else if ("name"equals(detailgetNodeName())) // 输出name
Systemout
println("姓名: " + detailgetTextContent());
else if ("money"equals(detailgetNodeName())) // 输出money
Systemout
println("余额: " + detailgetTextContent());
}
}
}
} catch (Exception e) {
eprintStackTrace();
}
}
}
一句两句说不清楚,给个代码大家交流哈,我也是学编程的
import javasql;
import javaio;
public class Test13{
public static void main(String[] args) throws Exception{
ClassforName("sunjdbcodbcJdbcOdbcDriver");
Connection conn = DriverManagergetConnection("jdbc:odbc:folkmusic");
Statement stmt = conncreateStatement();
ResultSet rs = stmtexecuteQuery("select from main");
ClassforName("oraclejdbcdriverOracleDriver");
Connection conn1 = DriverManagergetConnection("jdbc:oracle:thin:@127001:1521:java","java1","test123");
//conn1setAutoCommit(false);
while(rsnext()){
String content = rsgetString("content");
BufferedWriter bw = new BufferedWriter(new FileWriter("tmpfiletxt"));
bwwrite(content);
bwflush();
bwclose();
PreparedStatement stmt1 = conn1prepareStatement("insert into main (content) values ()");
InputStream is = new FileInputStream(new File("tmpfiletxt");
stmt1setBinaryStream(1,is,isavailable());
stmt1executeUpdate();
}
//conn1commit();
rsclose();
//stmt1close();
}
};
以上就是关于java jdom获取xml的所有子节点包括节点里的值全部的内容,包括:java jdom获取xml的所有子节点包括节点里的值、java问题,怎样从数据库动态获得jtree节点、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)