Reputation: 5989
I have this string in format of 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>
I want to split it to array of string just with the value and content
[0] objectA = ""
[1] command = Existing
[2] status = ok
[3] values = a lot of values....
I tried
result = result.replaceAll(">n<", "><"); //$NON-NLS-1$ //$NON-NLS-2$
Pattern pattern = Pattern.compile("<*?>*?</*?>"); //$NON-NLS-1$
but is is not working for me
Upvotes: 1
Views: 79
Reputation: 27346
Why not just use an 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.
}
Upvotes: 1