从字符串xml代码中读取XML元素 [英] Reading XML elements from string xml code
本文介绍了从字符串xml代码中读取XML元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个必须从WebService获得结果的ASP.Net网页(C#)。 WebService以下面的XML格式给出响应..
Hi,
I am developing one ASP.Net webpage (C#) which have to get result from WebService. The WebService giving response in XML format like below..
<?xml version='1.0' encoding='UTF-8'?>
<Response>
<ResponseCode>TS</ResponseCode>
<ResponseMessage>Transaction Success.Invalid SmartCard Number!<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN" "http TransID - 5602712201313 </ResponseMessage>
</Response>
这里就是我必须阅读元素值。为此,我使用以下代码...
Here Just i have to read the elements values. To do this, I am using following code...
string Resp= -- WebService Mehthod called --;
try
{
XElement myEle = XElement.Parse(Resp);
Response.Write("CODE : " + myEle.Element("ResponseCode").Value);
Response.Write("\nMSG : " + myEle.Element("ResponseMessage").Value);
}
catch(Exception ex)
{
Response.Write(ex);
}
但是......我在这里得到的异常是意外的DTD声明。第3行,第3位。
如何解决此问题..请帮助...
But.. Here i am getting Exception as "Unexpected DTD declaration. Line 3, position 3."
How can i resolve this issue.. Please help...
推荐答案
我认为您需要查看您的Web服务,或者您是如何从服务访问数据的 - 因为这看起来不像格式良好的XML数据。
您的DOCTYPE似乎是嵌入式的在ResponseMessage中以及其他一些东西,我希望它在所有实际数据之前。
I think you need to look at your web service, or how you are accessing the data from the service - because that does not look like well formed XML data.
Your DOCTYPE appears to be embedded in the ResponseMessage along with some other stuff, and I would expect it to precede all the actual data.
参考: - http://support.microsoft.com/kb/307548 [ ^
尝试使用正确的XML数据。
这可能会有所帮助
Refer:-http://support.microsoft.com/kb/307548[^
Try it with correct XML data.
This may help
这篇关于从字符串xml代码中读取XML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文