1

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

LaurentG
  • 10,440
  • 8
  • 47
  • 64
user1365697
  • 5,427
  • 15
  • 54
  • 86

1 Answers1

1

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.
}
christopher
  • 25,939
  • 5
  • 53
  • 88