如何在Android中解析xml类型的HTTPResponse
我有一个 Android 应用程序,我使用 POST 方法来获取响应。这是我的代码:
..........................................
HttpResponse httpResponse = httpclient.execute(httppost);
HttpEntity resEntity = httpResponse.getEntity();
这工作正常,我得到 xml 格式的响应,但我想解析该 xml 文件并获取节点值。我尝试了这个:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource());
doc.getDocumentElement().normalize();
但我不知道应该为 new InputSource()
提供什么,因为我必须使用 XML 类型 HTTPResponse 而不是 url。
谢谢 !!!
I have an android application where I use POST method to get a response. here is my code:
..........................................
HttpResponse httpResponse = httpclient.execute(httppost);
HttpEntity resEntity = httpResponse.getEntity();
this works fine and i get a response in xml format but i want to parse that xml file and get the node values. i tried this :
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource());
doc.getDocumentElement().normalize();
but I don't know what should give to new InputSource()
because I have to use a XML type HTTPResponse not a url.
Thanks !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好的,谢谢大家的回复。我刚刚找到了解决我的问题的方法。
http://www.rgagnon.com/javadetails/java-0573.html
ok thanks everyone for the replies. i just found out a way to overcome my problem.
http://www.rgagnon.com/javadetails/java-0573.html
尝试
try
您可以使用任何 XML 解析器(例如 SAX)来解析您的 XML 数据
You can use any XML parser like SAX to parse ur XML Data
如果您的响应采用 xml 字符串格式
if your response in xml string format follow