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()
}
}
}
补充:
System.out.print(foo.getChild("date").getText())
补充:
测试通过:
import java.io.*
import java.util.*
import org.jdom.*
import org.jdom.input.*
public class MyXMLReader2JDOM {
public static void main(String arge[]) {
try {
SAXBuilder builder = new SAXBuilder()
Document doc = builder.build(new File("D:/xmlcount.xml"))
Element foo = doc.getRootElement()
System.out.println("month-count : " + foo.getAttributeValue("month-count"))
System.out.println("total-count : " + foo.getAttributeValue("total-count"))
System.out.println("date : " + foo.getChild("date").getText())
} catch (Exception e) {
e.printStackTrace()
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)