title: Parsing Aadhaar XML data in Android
body: <p>In my Android application, the user needs to scan the Indian Aadhar QR code. After reading the QR code it returns following response. I can not parse it. Please help me fix this</p>
  
  <pre><code>String xml = "&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;PrintLetterBarcodeData uid="00X575452391" 
      name="XX" 
      gender="M" 
      yob="1992" 
      gname="XX" 
      co="S/O: XX" 
      house="4-175" 
      street="XX" 
      lm="XX" 
      vtc="XX" 
      po="XX" 
      dist="XX" 
      subdist="XX" 
      state="" 
      pc="XX" 
      dob="XX/XX/XXXX"/&gt;"
  </code></pre>
  
  <p><strong>Edit 1:</strong> Added what I tried for XML parsing.</p>
  
  <p>I have tried <a href="https://stackoverflow.com/questions/1823264/quickest-way-to-convert-xml-to-json-in-java">this solution</a>. But, it doesn't help me</p>
  
  <pre><code>    try{
          JSONObject xmlJSONObj = XML.toJSONObject(xml);
          String jsonPrettyPrintString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);
          System.out.println(jsonPrettyPrintString);
      } catch (JSONException je) {
          System.out.println(je.toString());
      }
  </code></pre>
  
  <p><strong>Edit 2:</strong> I have fixed it by myself using this code</p>
  
  <pre><code>public String xmlParser(String xml) {
      try{
          JSONObject xmlJSONObj = XML.toJSONObject(xml);
          return xmlJSONObj.toString(0);
      } catch (JSONException je) {
          return null;
      }
  }
  </code></pre>
  
  <p>To use <strong>XML.toJSONObject</strong>, you will first need to download the java-json lib and include it in your project. You can use this link to find a downloadable jar:</p>
  
  <p><a href="http://www.java2s.com/Code/Jar/j/Downloadjavajsonjar.htm" rel="nofollow noreferrer">http://www.java2s.com/Code/Jar/j/Downloadjavajsonjar.htm</a></p>
  
  <p>Place downloaded the file in app/libs folder and add the dependency</p>
  
  <pre><code>implementation fileTree(dir: 'libs', include: ['*.jar'])
  </code></pre>
  
  <p>Then you can use the code</p>