C# 缺少xml根元素
很抱歉这么简单,但我没有想到这一点,这是xml soap请求:C# 缺少xml根元素,c#,xml,C#,Xml,很抱歉这么简单,但我没有想到这一点,这是xml soap请求: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <TarifRespo
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<TarifResponse xmlns="http://www.april-technologies.com">
<TarifResult>
<Status>
<Summary>
<ResponseTechnicalLabel />
<ResponseTechnicalData>OK</ResponseTechnicalData>
</Summary>
</Status>
<BusinessData>
<IdentifiantProjet>1296483</IdentifiantProjet>
<Proposition>
<PropositionOutput>
<Ordre>1</Ordre>
<Produit>SanteEssentiel</Produit>
<Garantie>
<GarantieOutput>
<Libelle>Niveau 1</Libelle>
<CotisationMensuelle>5998</CotisationMensuelle>
</GarantieOutput>
</Garantie>
<ValiditeTarif>
<DateDebut>01/01/2014</DateDebut>
<DateFin>31/12/2014</DateFin>
</ValiditeTarif>
<OptionProduit />
</PropositionOutput>
</Proposition>
</BusinessData>
</TarifResult>
</TarifResponse>
</soap:Body>
</soap:Envelope>
???我能得到“CotisationMensuelle”的数据吗???我得到空数据,你能解决这个问题吗?你可以使用下面的方法
XNamespace foobar = "http://www.april-technologies.com";
var urlList = docxx.Descendants(foobar + "CotisationMensuelle")
.Select(x => (string)x)
.ToList();
Console.WriteLine(urlList.Count);
如果您试图使用元素
或元素
,则必须使用完整的层次结构
XNamespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
XNamespace ns1 = "http://www.april-technologies.com";
var CotisationMensuelle=(string)xml.Root
.Element(soapenv + "Body")
.Element(ns1 + "TarifResponse")
.Element(ns1 + "TarifResult")
.Element(ns1 + "BusinessData")
.Element(ns1 + "Proposition")
.Element(ns1 + "PropositionOutput")
.Element(ns1 + "Garantie")
.Element(ns1 + "GarantieOutput")
.Element(ns1 + "CotisationMensuelle");
“CotisationMensuelle”在GarantieOutput里面。。。例如:Root->TarifResult->BusinessData->Proposition->Garantie->GarantieOutput->cotisationmensualle您可以使用XPath 2:…编写如下内容:XmlDocument xmlDoc=new XmlDocument();负载xmlDoc.SelectSingleNode(“//CotisationMensuelle”).Value;或者类似的东西=)我已经测试了u-1st代码,感谢它的工作,但是当我将数据放入
rpMyRepeater1.DataSource=urlsist时,我有这样一条消息“[System.InvalidCastException]={”无法将'System.String'类型的对象强制转换为'System.Xml.XmlNode'。“}”;rpMyRepeater1.DataBind()代码>????我的代码出了什么问题?将Label1.Text=urlist.ToString()
更改为Label1.Text=urlist.First()
完整消息是'System.InvalidCastException:无法将'System.Char'类型的对象强制转换为'System.Xml.XmlNode'。在System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)在System.Web.UI.WebControls.Repeater.DataBind()在aprilService.Page_加载(对象发送方,EventArgs e)c:\WebSite1\WebSite1\aprilService.aspx.cs:第122行“rpMyRepeater1.DataBind();”`这是转发器绑定问题,您最好用转发器绑定相关代码问新问题
XNamespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
XNamespace ns1 = "http://www.april-technologies.com";
var CotisationMensuelle=(string)xml.Root
.Element(soapenv + "Body")
.Element(ns1 + "TarifResponse")
.Element(ns1 + "TarifResult")
.Element(ns1 + "BusinessData")
.Element(ns1 + "Proposition")
.Element(ns1 + "PropositionOutput")
.Element(ns1 + "Garantie")
.Element(ns1 + "GarantieOutput")
.Element(ns1 + "CotisationMensuelle");