我得到输出 xml 格式,可以访问约会-nbr,但我不能 eqid。我怎样才能获得 slot-start、slot-end、eqid。 > <appointment-nbr>494</appointment-nbr> <slot > slot-start="2018-07-16T12:31:00" slot-end="2018-07-16T13:00:00" /> > <appointment requires-xray="false" /> <container eqid="ASWU2705080" />这是我的代码:foreach (XmlNode node in appointmentsresponce){XmlElement flightEle = (XmlElement)node;XmlNodeList appointmentnbr = flightEle.GetElementsByTagName("appointment-nbr");XmlNodeList containerNodeList = flightEle.GetElementsByTagName("container");}
2 回答
慕村9548890
TA贡献1884条经验 获得超4个赞
尝试(因为您没有发布完整数据,所以我有点猜测):
foreach (XElement level1Element in XElement.Load(@"your_file.xml").Elements("appointment-nbr"))
{
foreach (XElement level2Element in level1Element.Elements("slot"))
{
Console.WriteLine(level1Element.Attribute("slot-start").Value);
}
}
饮歌长啸
TA贡献1951条经验 获得超3个赞
简单调用GetAttribute("AttributeName")您的XmlElement
所以:
var slotXml = appointmentsresponce.SelectSingleNode("//slot")
var startAttr = slotXml.GetAttribute("slot-start")
var endAttr = slotXml.GetAttribute("slot-end")
var containerXml = appointmentsresponce.SelectSingleNode("//container ")
var eqidAttr = containerXml .GetAttribute("eqid")
- 2 回答
- 0 关注
- 282 浏览
添加回答
举报
0/150
提交
取消