无法解析XML标记

时间:2013-07-16 17:30:43

标签: android xml parsing

这里我只是试图获取json一切正常但有点问题

我的XML:

 <match id="3" type="TEST" srs="The Ashes 2013" mchDesc="ENG vs AUS" mnum="1st Test" vcity="Nottingham" vcountry="England" grnd="Trent Bridge" inngCnt="4" datapath="http://synd.cricbuzz.com/j2me/1.0/match/2013/2013_ASHES/ENG_AUS_JUL10_JUL14/">
  <state mchState="complete" status="England won by 14 runs" TW="Eng" decisn="Batting" addnStatus="" splStatus=""></state>
   <Tm id="9" Name="Eng" sName="ENG" flag="1"/>
   <Tm id="4" Name="Aus" sName="AUS" flag="1"/>
   <Tme Dt="Jul 10 2013" stTme="10:00" enddt="Jul 14 2013"/>
     <mscr>
        <inngsdetail noofovers="0" rrr="0" crr="2.67" cprtshp=""/>
        <btTm id="4" sName="AUS">
           <Inngs desc="2nd Inns" r="296" Decl="0" FollowOn="0" ovrs="110.5" wkts="10"/>
           <Inngs desc="1st Inns" r="280" Decl="0" FollowOn="0" ovrs="64.5" wkts="10"/>
        </btTm>
        <blgTm id="9" sName="ENG">
           <Inngs desc="2nd Inns" r="375" Decl="0" FollowOn="0" ovrs="149.5" wkts="10"/>
           <Inngs desc="1st Inns" r="215" Decl="0" FollowOn="0" ovrs="59" wkts="10"/>
        </blgTm>
       </mscr>
  </match>

我的代码:

 try {
String mGetBufferData = getBufferData(Global.URL_MAIN);
InputStream stream = new ByteArrayInputStream(
mGetBufferData.getBytes("UTF-8"));

DocumentBuilder db = DocumentBuilderFactory.newInstance()
                .newDocumentBuilder();
Document doc = db.parse(stream);
     doc.getDocumentElement().normalize();
NodeList nodeList1 = doc.getElementsByTagName("match");
for (int i = 0; i < nodeList1.getLength(); i++) {
    Node node = nodeList1.item(i);
    Element fstElmnt = (Element) node;
    mMatchType = fstElmnt.getAttribute("srs");
    if (mMatchType.equalsIgnoreCase(Global.URL_MATCH_TYPE)) {

    location = fstElmnt.getAttribute("grnd") + ","
                            + fstElmnt.getAttribute("vcity");

    mInningCount = fstElmnt.getAttribute("inngCnt");

    // Fetch state node
    NodeList idList1 = fstElmnt
                    .getElementsByTagName("state");
    Element idElement1 = (Element) idList1.item(0);

    mStatusPartial = idElement1.getAttribute("mchState");
    mStatusFull = idElement1.getAttribute("status");

    try {
        // Fetch Tm Inngs details
    NodeList idList33 = fstElmnt.getElementsByTagName("btTm");
    for (int m = 0; m < idList33.getLength(); m++) {
    Node node4 = idList33.item(m);
    Element fourthElmnt = (Element) node4;
             arrayBettingTeamName.add(fourthElmnt.getAttribute("sName"));
    arrayType.add("betting");
}
} catch (Exception e) {
    e.printStackTrace();
}
try {
// Fetch Tm Inngs details
NodeList idList55 = fstElmnt.getElementsByTagName("blgTm");
for (int m = 0; m < idList55.getLength(); m++) {
    arrayType.add("bowling");
}

} catch (Exception e) {
    e.printStackTrace();
}

try {
    // Fetch Tm Inngs details
NodeList idList4 = fstElmnt .getElementsByTagName("Inngs");
for (int m = 0; m < idList4.getLength(); m++) {
    Node node4 = idList4.item(m);
    Element fourthElmnt = (Element) node4;
            arrayInndesc.add(fourthElmnt
                                    .getAttribute("desc"));
            arrayInnR.add(fourthElmnt.getAttribute("r"));

            arrayInnOver.add(fourthElmnt
                                    .getAttribute("ovrs"));
            arrayInnWikcet.add(fourthElmnt
                                    .getAttribute("wkts"));
                        }
            Log.e("arrayInnOver", arrayInnOver.toString());
            } catch (Exception e) {
                        e.printStackTrace();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

这里我在单循环中获取Inngs标签的数据但是我想要的是什么,我也想知道它来自btTmblgTm,我想要像

投注=第二旅馆(我得到的)

投注=第一旅馆(我得到的)

保龄球=第二旅馆(我得到的)

保龄球=第一旅馆(我得到的)

Sosmetime btTm可以有2个数据,而blgTm可以有1个数据

但在这里,我并没有得到这两个标签的长度。

0 个答案:

没有答案
相关问题