Skip to content

Instantly share code, notes, and snippets.

@yushulx
Last active November 25, 2022 09:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yushulx/a5f07891d5b22cfd24f21a111c80a008 to your computer and use it in GitHub Desktop.
Save yushulx/a5f07891d5b22cfd24f21a111c80a008 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<body>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@7.2.3-v2/dist/dbr.js"
data-productKeys="PRODUCT-KEY"></script>
<input id="uploadImage" type="file" accept="image/bmp,image/jpeg,image/png,image/gif">
<p id="results"></p>
<script>
document.getElementById('uploadImage').addEventListener('change', async function () {
$("#results").empty();
var files = this.files;
let reader = await Dynamsoft.BarcodeReader.createInstance();
let results = await reader.decode(files[0]);
if (results.length == 0) {
$("#results").append('No barcode detected!');
return;
}
for (let result of results) {
console.log(result.barcodeText);
try {
xmlDoc = $.parseXML(result.barcodeText),
$(xmlDoc).each(function (i, obj) {
console.log(i);
console.log(obj.documentElement.nodeName);
$data = $(xmlDoc).find(obj.documentElement.nodeName);
$data.each(function () {
$.each(this.attributes, function (i, attrib) {
var name = attrib.name;
var value = attrib.value;
console.log(name);
console.log(value);
info = '<div>' + name + ': ' + value + '</div>';
$("#results").append(info);
});
});
});
} catch (error) {
$("#results").append(error.message);
}
}
});
</script>
</body>
</html>
@vikas990
Copy link

this is very usefull but can you also explain that different aadhaar-card have different form of xml data how do we store all different type of data;
for example:-
in some aadhaar card location is stored as loc and in some locality how to solve that

@vikas990
Copy link

thanks.

@yushulx
Copy link
Author

yushulx commented May 11, 2020

@vikas990 it doesn't matter. Since it's XML, you can use any pair of keys and values. If there's no standard, you have to check both loc and locality.

@vikas990
Copy link

thanks.
its really usefull.

@HemantKumar9500
Copy link

But, your source code is not working Bro..........
plz do it another way ohk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment