Android 无法分析XML标记
这里我只是尝试获取json,一切正常,但有点小问题 我的XML:Android 无法分析XML标记,android,xml,parsing,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
<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();
}
试试看{
字符串mGetBufferData=getBufferData(Global.URL\u MAIN);
InputStream=新的ByteArrayInputStream(
mGetBufferData.getBytes(“UTF-8”);
DocumentBuilder db=DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
文档doc=db.parse(流);
doc.getDocumentElement().normalize();
NodeList nodeList1=doc.getElementsByTagName(“匹配”);
对于(int i=0;i
在这里,我在单循环中获取Inngs
标记的数据,但我真正想要的是什么,我也想知道它来自btTm
或blgTm
,我想要类似的东西
博彩=第二客栈(我得到)
博彩=第一客栈(我得到)
保龄球=第二客栈(我得到的)
保龄球=第一客栈(我得到)
SosmetimebtTm
可以有2个数据,blgTm
可以有1个数据
但是在这里,我无法获得这两个标签的长度。与其给我们一个代码的屏幕截图,不如给我们XML的实际内容?@Zact我需要btTm,blgTm的大小。使用getLength,但每个都得到1。什么?这和给我们一个答案有什么关系?@ZachLatta在我发布代码后,我已经尽力解决了这个问题