2013-02-08 65 views
0

我是C#的新手,我不确定是否所有的细节都在这里。从XmlElement返回XmlDocument

最初,我应该发送一个SOAP请求并将其响应读入数据集。

下面的代码工作:

DataSet ds = new DataSet(); 
cred.CredExecution mycredit = new cred.CredExecution(); 
ds = mycredit.RetrieveParsedRawData(inquiry, true); 
// I have the Web Reference "cred" added to the project. 
// Since I wasn't sure if a service reference was needed, I added that too. 

现在响应格式改变为XML,我不知道如何读它。

我改变了代码如下:

System.Xml.XmlDocument XmlDoc = new System.Xml.XmlDocument(); 
cred.CredExecution mycredit = new cred.CredExecution(); 
XmlDoc = mycredit.RetrieveParsedRawData(inquiry, true); 

但它失败,错误:

Cannot implicitly convert type 'System.Xml.XmlElement' to 'System.Xml.XmlDocument'

我试着使用:

System.Xml.XmlElement XmlEle = new System.Xml.XmlElement(); 

但系统不能说它是保护。

回答

3

从它的外观来看,RetrieveParsedRawData返回一个XmlElement而不是一个xmldocument。 所以这应该工作。

cred.CredExecution mycredit = new cred.CredExecution(); 
System.Xml.XmlElement XmlEle = mycredit.RetrieveParsedRawData(inquiry, true); 
System.Xml.XmlDocument XmlDoc = XmlEle.OwnerDocument; 
+0

感谢您的答复约翰尼。 – user2055287 2013-02-08 23:11:01

+0

当我按照你的建议更新了代码时,它没有发生错误。现在如何看到回应?当它是一个数据集时,我使用了“ds.WriteXml(filePath);”将XML写入文件。与XDoc,我没有看到任何选择WriteXML。所以我添加了“MessageBox.Show(XmlDoc.ToString());”并显示“System.Xml.XmlDocument”。从不同的工具中,我看到与 ... ... user2055287 2013-02-08 23:29:27

+0

要获取xml内容,您必须在XmlElement上调用InnerText或InnerXml。 你可以在这里找到XmlElement的文档:http://msdn.microsoft.com/en-us/library/system.xml.xmlelement.innerxml.aspx – 2013-02-09 07:18:18

相关问题