Code example for InputSource

0
            throw new UnsupportedTagException(techs, Utils.getHexString(tag.getId()));
    } 
 
    public static Card fromXml (String xml) throws Exception {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(new InputSource(new StringReader(xml)));
 
        Element rootElement = doc.getDocumentElement();
 
        CardType type      = CardType.class.getEnumConstants()[Integer.parseInt(rootElement.getAttribute("type"))];
        byte[]   id        = Utils.hexStringToByteArray(rootElement.getAttribute("id"));
        Date     scannedAt = rootElement.hasAttribute("scanned_at") ? new Date(Long.valueOf(rootElement.getAttribute("scanned_at"))) : new Date(0);
        switch (type) {
            case MifareDesfire:
                return DesfireCard.fromXml(id, scannedAt, rootElement);
            case CEPAS:
                return CEPASCard.fromXML(id, scannedAt, rootElement);
            case FeliCa:
                return FelicaCard.fromXml(id, scannedAt, rootElement);
            case MifareClassic:
                return ClassicCard.fromXml(id, scannedAt, rootElement);