KXML2解析 XMl 出错
qxkls 2008-07-08 09:02:59 <?xml version="1.0" encoding="GB2312" ?>
<object name="topviews" width="762" height="619" AutoSize="1">
<display backcolor="R:255,G:255,B:255" transparent="1" showico="0" icofilename=""
TipHob="" visible="1" />
<datasource stationid="0" datatagid="0" unit="" />
<script usescript="0" /> <objects>
<object name="156">
<location x="66.63502%" y="77.16156%" width="4.65514%" height="5.79138%" />
<datasource stationid="0" datatagid="0" unit="" />
</object>
<object name="158">
<location x="74.21625%" y="24.18751%" width="4.52214%" height="4.42870%" />
<datasource stationid="0" datatagid="0" unit="" />
</object>
<background filename="A4-2.jpg" RemainWidthHeightRate="0" />
</object>
代码
parser.nextTag();
parser.require(XmlPullParser.START_TAG, null, "object");
// String rootname = parser.getName();
for(int i= 0;i< parser.getAttributeCount();i++ )
{
System.out.println(parser.getAttributeName(i) +" " + (parser.getAttributeValue(i)));//输出 name=topviews width=762 height=619 AutoSize=1>正确
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
parser.nextTag();
String display = parser.getName();
for(int ii= 0;ii< parser.getAttributeCount();ii++ )
{
System.out.println(parser.getAttributeName(ii) +" " + (parser.getAttributeValue(ii)));// <display backcolor="R:255,G:255,B:255" transparent="1" showico="0" icofilename="" TipHob="" visible="1" /> 正确
}
//////////////////////////////////////////////////////////////////////////////////////////////////
parser.require(XmlPullParser.START_TAG, null, "datasource");
while(parser.nextTag()!=XmlPullParser.END_TAG)
{
for(int ii= 0;ii< parser.getAttributeCount();ii++ )
{
System.out.println(parser.getAttributeName(ii) +" " + (parser.getAttributeValue(ii)));// <display backcolor="R:255,G:255,B:255" transparent="1" showico="0" icofilename="" TipHob="" visible="1" />
}
}
为什么输出不了Datasource 和 <script usescript="0" /> 的属性和