<?xml version="1.0" encoding="UTF-8"?>
<commands>
<comand name="select" class="function">
Regular expression for select
</comand>
<comand name="delete" class="function2">
Regular expression for delete
</comand>
</commands>解析上面那种格式的xml配置文件,我要解析出name 和 class 的属性值
以及 "Regular expression for select ",怎么做??
<commands>
<comand name="select" class="function">
Regular expression for select
</comand>
<comand name="delete" class="function2">
Regular expression for delete
</comand>
</commands>解析上面那种格式的xml配置文件,我要解析出name 和 class 的属性值
以及 "Regular expression for select ",怎么做??
API里面有
LZ何必自己写呢
String xmlStr =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+"<commands>"
+"<comand name=\"select\" class=\"function\">"
+"Regular expression for select"
+"</comand>"
+"<comand name=\"delete\" class=\"function2\">"
+"Regular expression for delete"
+"</comand>"
+"</commands>";
InputStream xmlIo = new ByteArrayInputStream(xmlStr.getBytes());
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(xmlIo);
Element root = document.getRootElement();
List commands = root.getChildren();
for(int i=0;i<commands.size();i++){
Element comand = (Element)commands.get(i);
System.out.println(comand.getAttributeValue("class"));
System.out.println(comand.getAttributeValue("name"));
System.out.println(comand.getText());
}
需要用到jdom的jar包