当我从网上下载xml时,
会附加到我的xml。
如何从字符串中替换它。我知道我可以用
来做子串。但是有一个正则表达式来做这个..
正在运行代码
XmlParser parser = new XmlParser();
xml = parser.getXmlFromUrl(params[0]);
xml = xml.substring(3);
XmLParse方法
public String getXmlFromUrl(String url)
{
String xml = null;
try
{
//default http client
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
System.out.println("URL IN PARSER:==="+url+"====");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpentity = httpResponse.getEntity();
xml = EntityUtils.toString(httpentity);
Log.d("response", xml);
}
catch(UnsupportedEncodingException e)
{
e.printStackTrace();
}
catch (ClientProtocolException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return xml;
}
答案 0 :(得分:-1)
是utf-8中的BOM。试试这个:
xml = EntityUtils.toString(entity, "utf-8");