如何提取某标签下所有内容
1个回答
展开全部
// 此段代码需要引入dom4j的jar包
public static void main(String[] args) {
try {
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"
?><test><a>1</a><b>2</b>
<c>3</c></test>";
Document doc = DocumentHelper.parseText(xml);
Element testElement = doc.getRootElement();
String testxml = testElement.asXML();
String result = testxml.substring(testxml.indexOf(">") + 1, testxml.lastIndexOf("<"));
System.out.println(result);
} catch (DocumentException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"
?><test><a>1</a><b>2</b>
<c>3</c></test>";
Document doc = DocumentHelper.parseText(xml);
Element testElement = doc.getRootElement();
String testxml = testElement.asXML();
String result = testxml.substring(testxml.indexOf(">") + 1, testxml.lastIndexOf("<"));
System.out.println(result);
} catch (DocumentException e) {
e.printStackTrace();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询