【发布时间】:2013-12-19 16:33:26
【问题描述】:
很抱歉,这很简单,但这个是我躲避的,它是 xml 肥皂请求:
<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>
而代码c#是
XDocument docxx = XDocument.Parse(Session["xmlrs" + z + ""].ToString());
//This now holds the set of all elements named field
try
{
XNamespace foobar = "http://www.april-technologies.com";
var urlList = docxx.Descendants(foobar + "CotisationMensuelle")
.Select(x => (string)x)
.ToList();
Console.WriteLine(urlList);
rpMyRepeater1.DataSource = urlList;
rpMyRepeater1.DataBind();
}
catch(Exception ex) {}
???我能得到数据“CotisationMensuelle”吗???我得到空数据,我能解决这个问题吗?
【问题讨论】:
-
“CotisationMensuelle”在 GarantieOutput 里面...所以类似于:Root -> TarifResult -> BusinessData -> Proposition -> Garantie -> GarantieOutput -> CotisationMensualle
-
您可以使用 XPath 2:w3schools.com/xpath ...并编写如下内容: XmlDocument xmlDoc = new XmlDocument();加载... xmlDoc.SelectSingleNode ("//CotisationMensuelle").Value;或类似的东西 =)