-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?

4
  • Google: XML parser Java Commented Feb 13, 2015 at 9:54
  • have a look at an XML parser. If you have a more specific question later ask again. Commented Feb 13, 2015 at 9:54
  • 1
    possible duplicate of Java - Reading XML file Commented Feb 13, 2015 at 9:56
  • Here I have issue because prefix with element name is exist and i am new for this so. Commented Feb 13, 2015 at 10:56

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.