我是使用 SAX 解析的新手。我设法使用此代码获取返回的 xml 并将其绑定到我的 getter setter 上。
我的代码:
try {
/**
* Create a new instance of the SAX parser
**/
SAXParserFactory saxPF = SAXParserFactory.newInstance();
SAXParser saxP = saxPF.newSAXParser();
XMLReader xmlR = saxP.getXMLReader();
URL url = new URL(""); // URL of the XML
/**
* Create the Handler to handle each of the XML tags.
**/
XMLHandler myXMLHandler = new XMLHandler();
xmlR.setContentHandler(myXMLHandler);
xmlR.parse(new InputSource(url.openStream()));
} catch (Exception e) {
System.out.println(e);
}
data = XMLHandler.data;
现在我的问题是,如何在我的 php url 上传递参数。因为在我的 PHP 文件中,我需要一些数据,以便我可以验证它是否有效。
假设我需要登录电话的人的用户名?
在 DOM 方法上,我可以做这样的事情
XMLParser parser2 = new XMLParser();
parser2.getXmlFromUrl(URL_FBFRIEND);
//HTTP POST
String url_Getmembermob= URL_FBFRIEND ;
//String xml_getMembermob=null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url_Getmembermob);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("blah", "blah"));
nameValuePairs.add(new BasicNameValuePair("blah", "blah"));
nameValuePairs.add(new BasicNameValuePair("blah", "blah"));
nameValuePairs.add(new BasicNameValuePair("blah", "blah"));
//Log.i("nameValuePairs", "nameValuePairs=" + nameValuePairs);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpclient.execute(httppost);
HttpEntity httpEntity = httpResponse.getEntity();
FBFRIENDS = EntityUtils.toString(httpEntity);