如何用java获得xml文件中标签的属性列表值?
1.有xmlcount.xml文件。文件的内容如下:<?xmlversion="1.0"encoding="UTF-8"?><count-object-infmonth-...
1.有xmlcount.xml文件。文件的内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<count-object-inf month-count="34" total-count="34" temp-count="0" week-count="34" day-count="16" year-count="34"><date>2010-11-26T11:30:10.234+08:00</date></count-object-inf>
现在我想通过java去读取xmlcount.xml文件,然后获得其中标签名为:count-object-inf的多个属性,请问怎么做? 展开
<?xml version="1.0" encoding="UTF-8"?>
<count-object-inf month-count="34" total-count="34" temp-count="0" week-count="34" day-count="16" year-count="34"><date>2010-11-26T11:30:10.234+08:00</date></count-object-inf>
现在我想通过java去读取xmlcount.xml文件,然后获得其中标签名为:count-object-inf的多个属性,请问怎么做? 展开
1个回答
推荐于2017-05-17
展开全部
import java.io.*;
import java.util.*;
import org.jdom.*;
import org.jdom.input.*;public class MyXMLReader2JDOM {
public static void main(String arge[]) {
long lasting = System.currentTimeMillis();
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File("xmlcount.xml"));
Element foo = doc.getRootElement();
// List allChildren = foo.getChildren();
System.out.print( foo.getAttributeValue("month-count"));
System.out.println(foo.getAttributeValue("total-count"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.util.*;
import org.jdom.*;
import org.jdom.input.*;public class MyXMLReader2JDOM {
public static void main(String arge[]) {
long lasting = System.currentTimeMillis();
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File("xmlcount.xml"));
Element foo = doc.getRootElement();
// List allChildren = foo.getChildren();
System.out.print( foo.getAttributeValue("month-count"));
System.out.println(foo.getAttributeValue("total-count"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询