parsing an xml portion (without dom) etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
parsing an xml portion (without dom) etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

21 Aralık 2010 Salı

parsing an xml portion (without dom)

My problem is trying to parse an xml portion stored as a string. In trivial case, this is pretty easy by using indexOf() and lastIndexOf() methods, however, when the namespace is dynamic, the problem becomes a little tricky. For instance, when looking for foo, the data may come between
<foo>foo data < /foo> or
<ns1:foo>foo data< /ns1:foo> or
<ns2:foo>foo data< /ns2:foo> and so on..

In my case, i used such a simple solution:

String upToFooPre = fullMessage.substring(0,fullMessage.lastIndexOf("foo&gt ;"));
String upToFoo = upToFooPre.substring(0, upToFooPre.lastIndexOf("&lt ;"));
String foo = upToFoo.substring(upToFoo.lastIndexOf(("&gt ;")) + 4 );