1

我有这个 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$

但它不适合我

4

1 回答 1

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.
}
于 2013-08-20T07:48:48.737 回答