【发布时间】:2012-01-18 11:01:30
【问题描述】:
我想使用以下代码创建一个 Xml 文件并将其传递给 .net Web 服务。但是,我不知道如何在 .net Web 服务中获取和处理这个 XML 文件。你能帮我解决这个问题吗?
public void registration(String[] data) {
String line = "<UserData
Name=\"Username" Email = \"emaiAddress" Password = \"Password" +
"SecurityQuestion = \"Question" SAnswer = \"SAnswer"/>";
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(localhost + "UserData");
StringEntity se = new StringEntity(line, HTTP.UTF_8);
se.setContentType("text/xml");
httpPost.setEntity(se);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
line = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
}
}
我可以知道如何从 Web 服务中的这个 xml 获取属性。我尝试使用以下代码。但是卡住了,不知道如何进行。
//user registration
[WebMethod]
public void registration(XmlDocument data)
{
XmlDocument xml = data;
var username = xml.GetElementsByTagName("Username");
}
提前感谢您的帮助。
【问题讨论】:
标签: android asp.net-mvc web-services dom xml-parsing