-3

I am getting following code in response in xml

<.........>
   <stsuuser:Attribute name="authorized" type="urn:ibm:names:ITFIM:oauth:response:decision">
         <stsuuser:Value>TRUE</stsuuser:Value>
   </stsuuser:Attribute>   
<.........>

Now how I can get <stsuuser:Value> is true or false using Java?

Nikolay
  • 1,949
  • 18
  • 26
Uday A. Navapara
  • 1,237
  • 5
  • 20
  • 40

1 Answers1

0

There are quite literally dozens of libraries for Java that parse XML. But, I find JOOX by far the simplest to use. It lacks quite a few common features of other libraries, but unlike them, it's a joy to use. It provides you with a jQuery-like API (even has the $ function) and, in your case, you'd use it as follows:

import static org.joox.JOOX.$;
...
//Get the value of "authorized" attribute
$(...).xpath("//Attribute[@name='authorized']/Value").text();

The $ function will accepts a String, a file, a stream, a reader etc, so you can initialize with pretty much anything.

kaqqao
  • 12,984
  • 10
  • 64
  • 118