我有这个XML格式的字符串
<?xml version="1.0" encoding="UTF-8"?>n
<objectA>n
<command>Existing</command>n
<status>OK</status>n
<values>a lot of values....</values>n
</objectA>
我想用值和内容
将其拆分为字符串数组 [0] objectA = ""
[1] command = Existing
[2] status = ok
[3] values = a lot of values....
我试过
result = result.replaceAll(">n<", "><"); //$NON-NLS-1$ //$NON-NLS-2$
Pattern pattern = Pattern.compile("<*?>*?</*?>"); //$NON-NLS-1$
但是对我不起作用
答案 0 :(得分:1)
为什么不使用XML Parser?
Element docElem = document.getDocumentElement();
NodeList children = docElem.getChildNodes();
List<String> values = new ArrayList<String>();
for(int x = 0; x < children.getLength(); x++)
{
// Do what you want with children. That came out wrong.
}