主题:解析XML字符串的问题!
Java code
String xmlStr =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<gatherData>" +
"xmlns=\"http://www.w3school.com.cn\"" +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
"xsi:schemaLocation=\"gatherData.xsd\">" +
"<AID> 112 </AID>" +
"<DTIME>2008-4-16 </DTIME>" +
"<DATA1>55 </DATA1>" +
"<DATA2>44 </DATA2>";
已经可以提取标签值了,但是我想提取AID里的值112,DTIME里的2008-4-16... 应该用什么方法?
Java code
Document doc = sb.build(source);
Element root = doc.getRootElement();
System.out.println(root.getName());
List node = root.getChildren();
Namespace ns = root.getNamespace();
Element et = null;
for(int i = 0; i < node.size(); i++){
et = (Element)node.get(i);
s [i] = et.getName();
System.out.println(s[i]);
String xmlStr =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<gatherData>" +
"xmlns=\"http://www.w3school.com.cn\"" +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
"xsi:schemaLocation=\"gatherData.xsd\">" +
"<AID> 112 </AID>" +
"<DTIME>2008-4-16 </DTIME>" +
"<DATA1>55 </DATA1>" +
"<DATA2>44 </DATA2>";
已经可以提取标签值了,但是我想提取AID里的值112,DTIME里的2008-4-16... 应该用什么方法?
Java code
Document doc = sb.build(source);
Element root = doc.getRootElement();
System.out.println(root.getName());
List node = root.getChildren();
Namespace ns = root.getNamespace();
Element et = null;
for(int i = 0; i < node.size(); i++){
et = (Element)node.get(i);
s [i] = et.getName();
System.out.println(s[i]);