Skip to main content
 首页 » 编程设计

c#之从 XmlElement 返回 XmlDocument

2024年02月20日11pander-it

我是 C# 的新手,我不确定这里是否有所有详细信息。

最初,我应该发送 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(); 

但是系统失败说它被保护了。

请您参考如下方法:

从外观上看,RetrieveParsedRawData 返回一个 XmlElement 而不是 xmldocument。 所以这应该有效。

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