我有这个字符串XML得到的字符串XML节点值
string innerXml = @"<detail><WCFFaultExcepcion xmlns=""http://schemas.datacontract.org/2004/07/CIEL.DigiturnoMega.Entidades"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><ErrorId>b7e9d385-9118-4297-baca-db9ab00f3856</ErrorId><Message>Índice fuera de los límites de la matriz.</Message></WCFFaultExcepcion></detail>";
这是stringXML
<detail>
<WCFFaultExcepcion xmlns="http://schemas.datacontract.org/2004/07/CIEL.DigiturnoMega.Entidades" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ErrorId>b7e9d385-9118-4297-baca-db9ab00f3856</ErrorId>
<Message>Índice fuera de los límites de la matriz.</Message>
</WCFFaultExcepcion>
</detail>
我想要的是让细节变量的值,我试图用这个例子,但所有返回null零点计数,你能帮助我吗?
private static void Example()
{
string innerXml = @"<detail><WCFFaultExcepcion xmlns=""http://schemas.datacontract.org/2004/07/CIEL.DigiturnoMega.Entidades"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><ErrorId>b7e9d385-9118-4297-baca-db9ab00f3856</ErrorId><Message>Índice fuera de los límites de la matriz.</Message></WCFFaultExcepcion></detail>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(innerXml);
XmlNode node = (XmlNode)doc.DocumentElement;
XmlNode optionalNode = node.SelectSingleNode("/detail/WCFFaultExcepcion");
XmlNode optionalNode1 = node.SelectSingleNode("detail/WCFFaultExcepcion");
XmlNode optionalNode2 = node.SelectSingleNode("/detail/WCFFaultExcepcion/ErrorId");
XmlNode optionalNode3 = node.SelectSingleNode("detail/WCFFaultExcepcion/ErrorId");
XmlElement optional = doc.SelectSingleNode(@"/detail/WCFFaultExcepcion/ErrorId") as XmlElement;
XmlElement optiona2 = doc.SelectSingleNode(@"detail/WCFFaultExcepcion/ErrorId") as XmlElement;
XmlNode xNode = doc.DocumentElement.SelectNodes("ErrorId")[0];
XmlNodeList xnList = doc.SelectNodes("/detail/WCFFaultExcepcion");
XmlNodeList xnList1 = doc.SelectNodes("detail/WCFFaultExcepcion");
XmlNodeList xnList2 = doc.SelectNodes("/detail/WCFFaultExcepcion/ErrorId");
XmlNodeList xnList3 = doc.SelectNodes("detail/WCFFaultExcepcion/ErrorId");
}
我不明白你真正想要的到底。你能给我们一个例子吗?你是什么意思,“我想要的是获得详细标签的价值”。你期待节点吗?节点列表?一个字符串?一串字符串?以及它们应该是什么? – 2013-05-08 23:31:04