0

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

String xml = "<?xml version="1.0" encoding="UTF-8"?>
<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"/>"

Edit 1: Added what I tried for XML parsing.

I have tried this solution. But, it doesn't help me

    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());
    }

Edit 2: I have fixed it by myself using this code

public String xmlParser(String xml) {
    try{
        JSONObject xmlJSONObj = XML.toJSONObject(xml);
        return xmlJSONObj.toString(0);
    } catch (JSONException je) {
        return null;
    }
}

To use XML.toJSONObject, 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:

http://www.java2s.com/Code/Jar/j/Downloadjavajsonjar.htm

Place downloaded the file in app/libs folder and add the dependency

implementation fileTree(dir: 'libs', include: ['*.jar'])

Then you can use the code

Vignes
  • 390
  • 4
  • 11
  • 4
    What do you mean by "I can not parse it"? Is the question simply how to parse xml? Then where is your code? – f1sh May 02 '18 at 12:21
  • 1
    What you have tried so far? Show piece of code – Niranj Patel May 02 '18 at 12:22
  • Do not specify this kind of tags in your question tiitle you have to be specific to title that are related to technical terms like "Parsing of xml data in json format or whatso ever" specify do not specfiy the details unless you owned it or your is a part of your organisation if dont think "Adhhar" here is a product or something this can be misleading. Be carefull next time. – krishank Tripathi May 02 '18 at 12:31
  • I mean, I can not do XML parsing, Because it does not have the proper format @f1sh – Vignes May 02 '18 at 12:31
  • Edited my question. Please help me fix it – Vignes May 02 '18 at 12:47
  • What's the error that you're getting? I only see an extra " at the end that may be a typo. – RubioRic May 02 '18 at 12:48
  • https://stackoverflow.com/q/64341259/8362967 – LEGEND MORTAL Oct 13 '20 at 19:30

1 Answers1

0

Check below link for your XML format (aadhaar card parsing).

https://github.com/GovindaPaliwal/Aadhaar-Card-Reader

Important Note : This is old XML format (aadhaar card QR Code). UIDAI time to time update there QR Code Logic. Now a day they provide 2 type of QR code in card. i.e.

  1. The large one contains your photograph & demographic information

  2. Small one contains only your demographic information.

Both are digitally signed by UIDAI.

Govinda P
  • 3,261
  • 5
  • 22
  • 43