Wednesday, April 23, 2014

android using SAX parsing the returned data error webService


This is two days in debug android's sax resolve themselves with axis2 webService do a sql query returns data, but have been unable to enter the wrong analytical startElement


Here is the code (on a button to display the data parsing):
 testButton.setOnClickListener (new OnClickListener () {

@ Override
public void onClick (View v) {
/ / TODO Auto-generated method stub

try {
SoapObject request1 = new SoapObject (space, "queryStudents");
/ / Request1.addProperty ("name", "Bob");
HttpTransportSE ht1 = new HttpTransportSE (
"Http://192.168.1.3:8080/axis2/services/MyService");
ht1.debug = true;
SoapSerializationEnvelope envelope1 = new SoapSerializationEnvelope (
SoapEnvelope.VER11);
envelope1.bodyOut = request1;
envelope1.dotNet = true;
envelope1.setOutputSoapObject (request1);
/ / Envelope1.encodingStyle = "UTF-8";

ht1.call (space_name, envelope1);

/ / The return value (xml format) forced into Object type
/ / Object object1 = (Object) envelope1.getResponse ();
SoapObject object1 = (SoapObject) envelope1.bodyIn;
String info2 = object1.getProperty (0) toString ();.
System.out.println ("info2 --->" + info2);
/ / Return values ​​for a plurality of content that can be considered parsing xml
String info1 = envelope1.bodyIn.toString ();
System.out.println ("result --->" + info1);
try {
/ / Create a SAXParserFactory (wording has ordained)
SAXParserFactory factory = SAXParserFactory.newInstance ();
/ / Create an XML object (the wording has ordained) Role: Progressive scan xml file
XMLReader reader = factory.newSAXParser () getXMLReader ();.
/ / Set the content processor to XMLreader use inheritance to implement some method DefaultHandler interfaces inside
reader.setContentHandler (new MycontenHander ());
/ / Start parsing an XML document
reader.parse (new InputSource (new StringReader (info1)));
/ / Reader.parse (inputSource);
}
catch (Exception e) {
e.printStackTrace ();
}

} Catch (HttpResponseException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
} Catch (IOException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
} Catch (XmlPullParserException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}

}
});




Here is the data returned webService:
  

Nanjing
1
Xiao Ming
1
119


Tibet
2
Guo
2
110


Korea
3
Kun brother
3
117


Canada
4
Joe Smith
0
120


Copy the code


Is shown in the error saying:
04-21 05:11:35.767: WARN / System.err (1401): at com.example.webtestactivity.MainActivity $ 2.onClick (MainActivity.java: 96)
That is the phrase: reader.parse (new InputSource (new StringReader (info1)));
The wrong info1, but I do not know what the problem is
There are two:
04-21 05:11:35.716: WARN / System.err (1401): org.apache.harmony.xml.ExpatParser $ ParseException: At line 1, column 21: not well-formed (invalid token)
This is to say that my data format webService returned there a problem? ? Or? ?





This is the information printed:
04-21 05:11:35.695: INFO / System.out (1401): info2 ---> Student {address = Nanjing; id = 1; name = Xiao Ming; number = 1; tel = 119;}


04-21 05:11:35.695: INFO / System.out (1401): result ---> queryStudentsResponse {return = Student {address = Nanjing; id = 1; name = Xiao Ming; number = 1; tel = 119; }; return = Student {address = Tibet; id = 2; name = Guo; number = 2; tel = 110;}; return = Student {address = Korea; id = 3; name = Kun brother; number = 3; tel = 117;}; return = Student {address = Canada; id = 4; name = Joe Smith; number = 0; tel = 120;};}

04-21 05:11:35.716: INFO / System.out (1401): ------ begin -----


Then they can not enter the startElement a

This data is a problem with wood ah? ? Seek guidance

startElement function:
 @ Override 
public void startElement (String uri, String localName, String qName,
Attributes atts) throws SAXException {
/ / TODO Auto-generated method stub
System.out.println ("Qname ------>" + qName);
System.out.println ("Localname ------>" + localName);
tagName = localName;
if (localName.equals ("return")) {
for (int i = 0; i System.out.println (atts.getLocalName (i) + atts.getValue (i));
}
}

}
Copy the code


Speed ​​come ah! ! ! !
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Their own roof

No comments:

Post a Comment