Java 如何根据参数分割html数据

Java 如何根据参数分割html数据,java,android,xml-parsing,Java,Android,Xml Parsing,我已经扫描了Aadhar卡二维码,扫描数据如下: <PrintLetterBarcodeData uid="741647613082" name="Pasikanti Enosh Kumar" gender="M" yob="1992" co="S/O Srinivas" house="SPLD-986" street="MALLARAM" loc="P V COLONY" vtc="Manuguru" po="P.V.Township" dist="Khamma

我已经扫描了Aadhar卡二维码,扫描数据如下:

<PrintLetterBarcodeData 
    uid="741647613082" name="Pasikanti Enosh Kumar" gender="M"
    yob="1992" co="S/O Srinivas" house="SPLD-986" street="MALLARAM"
    loc="P V COLONY" vtc="Manuguru" po="P.V.Township" dist="Khammam"
    state="Andhra Pradesh" pc="507125">


我想分割数据,并希望获得每个属性,如名称、id、dob等。我如何才能做到这一点

您需要使用的是
javax.xml.parsers.DocumentBuilderFactory
org.w3c.dom

String sStringToParse;

// put your XML value into the sStringToParse variable
sStringToParse = new String("<PrintLetterBarcodeData uid='741647613082' name='Pasikanti Enosh Kumar' gender='M' yob='1992' co='S/O Srinivas' house='SPLD-986' street='MALLARAM' loc='P V COLONY' vtc='Manuguru' po='P.V.Township' dist='Khammam' state='Andhra Pradesh' pc='507125'/>");

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new ByteArrayInputStream(sStringToParse.getBytes("utf-8")));
NodeList nlRecords = doc.getElementsByTagName("PrintLetterBarcodeData");

int num = nlRecords.getLength();

for (int i = 0; i < num; i++) {
    Element node = (Element) nlRecords.item(i);

    System.out.println("List attributes for node: " + node.getNodeName());

    // get a map containing the attributes of this node
    NamedNodeMap attributes = node.getAttributes();

    // get the number of nodes in this map
    int numAttrs = attributes.getLength();

    for (int j = 0; j < numAttrs; j++) {
        Attr attr = (Attr) attributes.item(j);

        String attrName = attr.getNodeName();
        String attrValue = attr.getNodeValue();

        // Do your stuff here
        System.out.println("Found attribute: " + attrName + " with value: " + attrValue);

    }

}
字符串sStringToParse;
//将XML值放入sStringToParse变量中
sStringToParse=新字符串(“”);
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.parse(新的ByteArrayInputStream(sStringToParse.getBytes(“utf-8”));
NodeList nlRecords=doc.getElementsByTagName(“PrintLetterBarcodeData”);
int num=nlRecords.getLength();
for(int i=0;i

阅读更多关于这方面的内容。

请更具体一些。请参阅我尝试过的感谢Nikhil Girraj的答案,但在我的数据中,所有属性都在一个标记中。谢谢你,非常感谢Nikhil Girraj,这正是我需要的