java中xml出现重复标签节点,整么解决啊? 50
<?xmlversion=”1.0”encoding=”UTF-8”?><ebank><head><serviceId>EPBC0002</serviceId><cltR...
<?xml version=”1.0” encoding=”UTF-8”?>
<ebank>
<head>
<serviceId>EPBC0002</serviceId>
<cltReqChannel>LN</cltReqChannel>
<cltReqTime>20140411112630</cltReqTime>
<repCode>000</repCode>
<repMsg/>
</head>
<body>
<list>
<record>
<customerId>111</customerId>
<accountNo>222</accountNo>
</record>
<record>
<customerId>333</customerId>
<accountNo>444</accountNo>
</record>
<record>
<customerId>555</customerId>
<accountNo>666</accountNo>
</record>
</list>
</body>
</ebank>
请问大家,这样如何解析出来啊?
获取:customerId,accountNo的值。我获取只能获取第一个,剩下两个获取不到
求教。。。 展开
<ebank>
<head>
<serviceId>EPBC0002</serviceId>
<cltReqChannel>LN</cltReqChannel>
<cltReqTime>20140411112630</cltReqTime>
<repCode>000</repCode>
<repMsg/>
</head>
<body>
<list>
<record>
<customerId>111</customerId>
<accountNo>222</accountNo>
</record>
<record>
<customerId>333</customerId>
<accountNo>444</accountNo>
</record>
<record>
<customerId>555</customerId>
<accountNo>666</accountNo>
</record>
</list>
</body>
</ebank>
请问大家,这样如何解析出来啊?
获取:customerId,accountNo的值。我获取只能获取第一个,剩下两个获取不到
求教。。。 展开
2个回答
展开全部
Element list= eb.element("list");
Iterator<?> records= out.elementIterator("record");
Element record;
while (records.hasNext()) {
record = records.next();
String xmlText = rd.element("customerId").getText();
.........
}
用的是dom4j,如果你用的其他的插件或没有这个jar包是不能用的
Iterator<?> records= out.elementIterator("record");
Element record;
while (records.hasNext()) {
record = records.next();
String xmlText = rd.element("customerId").getText();
.........
}
用的是dom4j,如果你用的其他的插件或没有这个jar包是不能用的
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Reader reader = new InputStreamReader(con
.getInputStream());
SAXReader sax = new SAXReader();
// sax.setEncoding("GBK");
Document document = sax.read(reader);
document.setXMLEncoding("GBK");
Element root = document.getRootElement();
// Document doc = reader.read(read);
// Element root = doc.getRootElement();
readNode(root, "");
public static void readNode(Element root, String prefix) {
if (root == null) return;
// 获取属性
List attrs = root.attributes();
if (attrs != null && attrs.size() > 0) {
System.err.print(prefix);
for (Attribute attr : attrs) {
System.err.print(attr.getValue() + " ");
}
System.err.println();
}
// 获取他的子节点
List childNodes = root.elements();
prefix += "\t";
for (Element e : childNodes) {
//输出内容
System.err.println(e.getName()+":"+e.getData());
readNode(e, prefix);
}
}
.getInputStream());
SAXReader sax = new SAXReader();
// sax.setEncoding("GBK");
Document document = sax.read(reader);
document.setXMLEncoding("GBK");
Element root = document.getRootElement();
// Document doc = reader.read(read);
// Element root = doc.getRootElement();
readNode(root, "");
public static void readNode(Element root, String prefix) {
if (root == null) return;
// 获取属性
List attrs = root.attributes();
if (attrs != null && attrs.size() > 0) {
System.err.print(prefix);
for (Attribute attr : attrs) {
System.err.print(attr.getValue() + " ");
}
System.err.println();
}
// 获取他的子节点
List childNodes = root.elements();
prefix += "\t";
for (Element e : childNodes) {
//输出内容
System.err.println(e.getName()+":"+e.getData());
readNode(e, prefix);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |