我想解析xml
数据。解析后的数据格式为Inputstream
。
当我开始解析时,我收到错误column not well formed...
我的代码
public class Cafezeeapps extends Activity {
String response11;
TextView ress;
SaopCall call;
InputStream source;
Cafezeelist cafelist;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cafezeeapps);
ress=(TextView) findViewById(R.id.textView1);
call=new SaopCall();
source=call.Call();
SAXParserFactory spf = SAXParserFactory.newInstance();
try
{
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
Log.i("hii", "hello");
CafezeeXmlHandler xmlhandler=new CafezeeXmlHandler();
xr.setContentHandler(xmlhandler);
Reader isr = new InputStreamReader(source, "UTF-8");
InputSource is=new InputSource(isr);
is.setEncoding("UTF-8");
Log.i("helllo", "hiiiiiiiiiiiii");
// BufferedReader r = new BufferedReader(new InputStreamReader(source));
// StringBuilder total = new StringBuilder();
// String line;
// while ((line = r.readLine()) != null) {
// total.append(line);
// }
// ress.setText(total);
try{
xr.parse(is);
}
catch(SAXParseException e)
{
Log.i("SAX", "sax exception...");
e.printStackTrace();
}
cafelist=CafezeeXmlHandler.getProgramList();
Toast.makeText(getApplicationContext(),"size is"+ cafelist.getmachineip().size(), 1000).show();
}
catch(Exception e)
{
e.printStackTrace();
}
}
CafezeeXML处理程序
package com.example.cafezeeapplication;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import android.util.Log;
public class CafezeeXmlHandler extends DefaultHandler{
Boolean currentElement = false;
public static Cafezeelist cafezeelist = null;
String currentValue = null;
//get the cafe ze list..
public static Cafezeelist getProgramList()
{
return cafezeelist;
}
//set the cafe zee list
public static void setProgramList(Cafezeelist cafezeelist)
{
CafezeeXmlHandler.cafezeelist = cafezeelist;
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
super.startElement(uri, localName, qName, attributes);
currentElement=true;
//set up for hierarchy scan to place data within category
if(localName.equals("DataSet"))
{
Log.i("inside","demoooo");
cafezeelist=new Cafezeelist();
}
else if(localName.equals("Table"))
{
String attr=attributes.getValue(0);
String attr1=attributes.getValue(1);
cafezeelist.setTable(attr);
cafezeelist.setrowOrder(attr1);
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
// TODO Auto-generated method stub
super.endElement(uri, localName, qName);
currentElement=false;
/** set value */
if (localName.equalsIgnoreCase("MachineIP"))
{
cafezeelist.setmachineip(currentValue);
}
else
{
//blabalab...
}
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
// TODO Auto-generated method stub
super.characters(ch, start, length);
if (currentElement) {
currentValue = new String(ch, start, length);
currentElement = false;
}
}
}
解析XMl
<?xml version="1.0" encoding="utf-8"?>
<DataSet>
<xs:schema id="Result" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Result" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="SystemDateTime" type="xs:dateTime" minOccurs="0" />
<xs:element name="CafeDateTime" type="xs:dateTime" minOccurs="0" />
<xs:element name="LicenseNumber" type="xs:string" minOccurs="0" />
<xs:element name="MachineIP" type="xs:string" minOccurs="0" />
<xs:element name="TotalClients" type="xs:int" minOccurs="0" />
<xs:element name="IdleClients" type="xs:int" minOccurs="0" />
<xs:element name="BusyClients" type="xs:int" minOccurs="0" />
<xs:element name="DummyIdle" type="xs:int" minOccurs="0" />
<xs:element name="DummyBusy" type="xs:int" minOccurs="0" />
<xs:element name="PCUsageSessions" type="xs:int" minOccurs="0" />
<xs:element name="PCUsageMinutes" type="xs:int" minOccurs="0" />
<xs:element name="SessionMessage" type="xs:string" minOccurs="0" />
<xs:element name="CreatedBy" type="xs:int" minOccurs="0" />
<xs:element name="CreatedDate" type="xs:dateTime" minOccurs="0" />
<xs:element name="Cybercafe" type="xs:string" minOccurs="0" />
<xs:element name="Email" type="xs:string" minOccurs="0" />
<xs:element name="AdminPassword" type="xs:string" minOccurs="0" />
<xs:element name="MajorVersion" type="xs:short" minOccurs="0" />
<xs:element name="MinorVersion" type="xs:short" minOccurs="0" />
<xs:element name="SalesAmount" type="xs:decimal" minOccurs="0" />
<xs:element name="PurchasesAmount" type="xs:decimal" minOccurs="0" />
<xs:element name="Revision" type="xs:int" minOccurs="0" />
<xs:element name="CZLicense" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<Result>
<Table diffgr:id="Table1" msdata:rowOrder="0">
<SystemDateTime>2012-09-20T00:00:00-06:00</SystemDateTime>
<CafeDateTime>2012-09-18T11:01:54-06:00</CafeDateTime>
<LicenseNumber>cc</LicenseNumber>
<MachineIP>192.168.13.167</MachineIP>
<TotalClients>0</TotalClients>
<IdleClients>0</IdleClients>
<BusyClients>0</BusyClients>
<DummyIdle>0</DummyIdle>
<DummyBusy>0</DummyBusy>
<PCUsageSessions>0</PCUsageSessions>
<PCUsageMinutes>0</PCUsageMinutes>
<SessionMessage>LVCLPRLbSCTC</SessionMessage>
<CreatedBy>1</CreatedBy>
<CreatedDate>2012-09-20T00:00:00-06:00</CreatedDate>
<Cybercafe>Cyber Cafe Name</Cybercafe>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<MajorVersion>1</MajorVersion>
<MinorVersion>0</MinorVersion>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
<Revision>0</Revision>
<CZLicense />
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="1">
<SystemDateTime>2012-09-20T00:00:00-06:00</SystemDateTime>
<CafeDateTime>2012-09-18T11:01:54-06:00</CafeDateTime>
<LicenseNumber>cc</LicenseNumber>
<MachineIP>192.168.13.167</MachineIP>
<TotalClients>0</TotalClients>
<IdleClients>0</IdleClients>
<BusyClients>0</BusyClients>
<DummyIdle>0</DummyIdle>
<DummyBusy>0</DummyBusy>
<PCUsageSessions>0</PCUsageSessions>
<PCUsageMinutes>0</PCUsageMinutes>
<SessionMessage>LVCLPRLbSCTC</SessionMessage>
<CreatedBy>1</CreatedBy>
<CreatedDate>2012-09-20T00:00:00-06:00</CreatedDate>
<Cybercafe>Cyber Cafe Name</Cybercafe>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<MajorVersion>1</MajorVersion>
<MinorVersion>0</MinorVersion>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
<Revision>0</Revision>
<CZLicense />
</Table>
<Table diffgr:id="Table3" msdata:rowOrder="2">
<SystemDateTime>2012-09-20T00:00:00-06:00</SystemDateTime>
<CafeDateTime>2012-09-18T11:01:54-06:00</CafeDateTime>
<LicenseNumber>cc</LicenseNumber>
<MachineIP>192.168.13.167</MachineIP>
<TotalClients>0</TotalClients>
<IdleClients>0</IdleClients>
<BusyClients>0</BusyClients>
<DummyIdle>0</DummyIdle>
<DummyBusy>0</DummyBusy>
<PCUsageSessions>0</PCUsageSessions>
<PCUsageMinutes>0</PCUsageMinutes>
<SessionMessage>LVCLPRLbSCTC</SessionMessage>
<CreatedBy>1</CreatedBy>
<CreatedDate>2012-09-20T00:00:00-06:00</CreatedDate>
<Cybercafe>Cyber Cafe Name</Cybercafe>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<MajorVersion>1</MajorVersion>
<MinorVersion>0</MinorVersion>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
<Revision>0</Revision>
<CZLicense />
</Table>
<Table diffgr:id="Table4" msdata:rowOrder="3">
<SystemDateTime>2012-09-20T00:00:00-06:00</SystemDateTime>
<CafeDateTime>2012-09-18T11:01:54-06:00</CafeDateTime>
<LicenseNumber>Lic012</LicenseNumber>
<MachineIP>192.168.13.167</MachineIP>
<TotalClients>0</TotalClients>
<IdleClients>0</IdleClients>
<BusyClients>0</BusyClients>
<DummyIdle>0</DummyIdle>
<DummyBusy>0</DummyBusy>
<PCUsageSessions>0</PCUsageSessions>
<PCUsageMinutes>0</PCUsageMinutes>
<SessionMessage>LVCLPRLbSCTC</SessionMessage>
<CreatedBy>1</CreatedBy>
<CreatedDate>2012-09-20T00:00:00-06:00</CreatedDate>
<Cybercafe>Cyber Cafe Name</Cybercafe>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<MajorVersion>1</MajorVersion>
<MinorVersion>0</MinorVersion>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
<Revision>0</Revision>
<CZLicense />
</Table>
<Table diffgr:id="Table5" msdata:rowOrder="4">
<SystemDateTime>2012-09-20T00:00:00-06:00</SystemDateTime>
<CafeDateTime>2012-09-18T11:01:54-06:00</CafeDateTime>
<LicenseNumber>cc</LicenseNumber>
<MachineIP>192.168.13.167</MachineIP>
<TotalClients>0</TotalClients>
<IdleClients>0</IdleClients>
<BusyClients>0</BusyClients>
<DummyIdle>0</DummyIdle>
<DummyBusy>0</DummyBusy>
<PCUsageSessions>0</PCUsageSessions>
<PCUsageMinutes>0</PCUsageMinutes>
<SessionMessage>LVCLPRLbSCTC</SessionMessage>
<CreatedBy>1</CreatedBy>
<CreatedDate>2012-09-20T00:00:00-06:00</CreatedDate>
<Cybercafe>Cyber Cafe Name</Cybercafe>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<MajorVersion>1</MajorVersion>
<MinorVersion>0</MinorVersion>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
<Revision>0</Revision>
<CZLicense />
</Table>
<Table diffgr:id="Table6" msdata:rowOrder="5">
<SystemDateTime>2012-09-20T00:00:00-06:00</SystemDateTime>
<CafeDateTime>2012-09-18T11:01:54-06:00</CafeDateTime>
<LicenseNumber>Lic012</LicenseNumber>
<MachineIP>192.168.13.167</MachineIP>
<TotalClients>0</TotalClients>
<IdleClients>0</IdleClients>
<BusyClients>0</BusyClients>
<DummyIdle>0</DummyIdle>
<DummyBusy>0</DummyBusy>
<PCUsageSessions>0</PCUsageSessions>
<PCUsageMinutes>0</PCUsageMinutes>
<SessionMessage>LVCLPRLbSCTC</SessionMessage>
<CreatedBy>1</CreatedBy>
<CreatedDate>2012-09-20T00:00:00-06:00</CreatedDate>
<Cybercafe>Cyber Cafe Name</Cybercafe>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<MajorVersion>1</MajorVersion>
<MinorVersion>0</MinorVersion>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
<Revision>0</Revision>
<CZLicense />
</Table>
<Table diffgr:id="Table7" msdata:rowOrder="6">
<SystemDateTime>2012-09-20T00:00:00-06:00</SystemDateTime>
<CafeDateTime>2012-09-18T11:01:54-06:00</CafeDateTime>
<LicenseNumber>Lic012</LicenseNumber>
<MachineIP>192.168.13.167</MachineIP>
<TotalClients>0</TotalClients>
<IdleClients>0</IdleClients>
<BusyClients>0</BusyClients>
<DummyIdle>0</DummyIdle>
<DummyBusy>0</DummyBusy>
<PCUsageSessions>0</PCUsageSessions>
<PCUsageMinutes>0</PCUsageMinutes>
<SessionMessage>LVCLPRLbSCTC</SessionMessage>
<CreatedBy>1</CreatedBy>
<CreatedDate>2012-09-20T00:00:00-06:00</CreatedDate>
<Cybercafe>Cyber Cafe Name</Cybercafe>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<MajorVersion>1</MajorVersion>
<MinorVersion>0</MinorVersion>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
<Revision>0</Revision>
<CZLicense />
</Table>
<Table diffgr:id="Table8" msdata:rowOrder="7">
<SystemDateTime>2012-09-20T00:00:00-06:00</SystemDateTime>
<CafeDateTime>2012-09-18T11:01:54-06:00</CafeDateTime>
<LicenseNumber>Lic012</LicenseNumber>
<MachineIP>192.168.13.167</MachineIP>
<TotalClients>0</TotalClients>
<IdleClients>0</IdleClients>
<BusyClients>0</BusyClients>
<DummyIdle>0</DummyIdle>
<DummyBusy>0</DummyBusy>
<PCUsageSessions>0</PCUsageSessions>
<PCUsageMinutes>0</PCUsageMinutes>
<SessionMessage>LVCLPRLbSCTC</SessionMessage>
<CreatedBy>1</CreatedBy>
<CreatedDate>2012-09-20T00:00:00-06:00</CreatedDate>
<Cybercafe>Cyber Cafe Name</Cybercafe>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<MajorVersion>1</MajorVersion>
<MinorVersion>0</MinorVersion>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
<Revision>0</Revision>
<CZLicense />
</Table>
<Table diffgr:id="Table9" msdata:rowOrder="8">
<SystemDateTime>2012-09-20T00:00:00-06:00</SystemDateTime>
<CafeDateTime>2012-09-18T11:01:54-06:00</CafeDateTime>
<LicenseNumber>Lic012</LicenseNumber>
<MachineIP>192.168.13.167</MachineIP>
<TotalClients>0</TotalClients>
<IdleClients>0</IdleClients>
<BusyClients>0</BusyClients>
<DummyIdle>0</DummyIdle>
<DummyBusy>0</DummyBusy>
<PCUsageSessions>0</PCUsageSessions>
<PCUsageMinutes>0</PCUsageMinutes>
<SessionMessage>LVCLPRLbSCTC</SessionMessage>
<CreatedBy>1</CreatedBy>
<CreatedDate>2012-09-20T00:00:00-06:00</CreatedDate>
<Cybercafe>Cyber Cafe Name</Cybercafe>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<MajorVersion>1</MajorVersion>
<MinorVersion>0</MinorVersion>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
<Revision>0</Revision>
<CZLicense />
</Table>
<Table diffgr:id="Table10" msdata:rowOrder="9">
<SystemDateTime>2012-09-20T00:00:00-06:00</SystemDateTime>
<CafeDateTime>2012-09-18T11:01:54-06:00</CafeDateTime>
<LicenseNumber>Lic012</LicenseNumber>
<MachineIP>192.168.13.167</MachineIP>
<TotalClients>0</TotalClients>
<IdleClients>0</IdleClients>
<BusyClients>0</BusyClients>
<DummyIdle>0</DummyIdle>
<DummyBusy>0</DummyBusy>
<PCUsageSessions>0</PCUsageSessions>
<PCUsageMinutes>0</PCUsageMinutes>
<SessionMessage>LVCLPRLbSCTC</SessionMessage>
<CreatedBy>1</CreatedBy>
<CreatedDate>2012-09-20T00:00:00-06:00</CreatedDate>
<Cybercafe>Cyber Cafe Name</Cybercafe>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<MajorVersion>1</MajorVersion>
<MinorVersion>0</MinorVersion>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
<Revision>0</Revision>
<CZLicense />
</Table>
<Table diffgr:id="Table11" msdata:rowOrder="10">
<SystemDateTime>2012-09-20T00:00:00-06:00</SystemDateTime>
<CafeDateTime>2012-09-18T11:01:54-06:00</CafeDateTime>
<LicenseNumber>Lic012</LicenseNumber>
<MachineIP>192.168.13.167</MachineIP>
<TotalClients>0</TotalClients>
<IdleClients>0</IdleClients>
<BusyClients>0</BusyClients>
<DummyIdle>0</DummyIdle>
<DummyBusy>0</DummyBusy>
<PCUsageSessions>0</PCUsageSessions>
<PCUsageMinutes>0</PCUsageMinutes>
<SessionMessage>LVCLPRLbSCTC</SessionMessage>
<CreatedBy>1</CreatedBy>
<CreatedDate>2012-09-20T00:00:00-06:00</CreatedDate>
<Cybercafe>Cyber Cafe Name</Cybercafe>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<MajorVersion>1</MajorVersion>
<MinorVersion>0</MinorVersion>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
<Revision>0</Revision>
<CZLicense />
</Table>
</Result>
</diffgr:diffgram>
</DataSet>
哪一个适合解析数据dom
或sax
解析器?
无法解析数据。谢谢所有回复..