-2

I am getting output xml format in that can able to access appointment-nbr, but I am not able to eqid. How can I get 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" />

This is my code:

foreach (XmlNode node in appointmentsresponce){
XmlElement flightEle = (XmlElement)node;
XmlNodeList appointmentnbr = flightEle.GetElementsByTagName("appointment-nbr");
XmlNodeList containerNodeList = flightEle.GetElementsByTagName("container");
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Dileep
  • 81
  • 1
  • 1
  • 5

2 Answers2

0

Try (I'm guessing a bit since you didn't post the full data):

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);
    }
}
Afonso
  • 323
  • 4
  • 14
  • XmlDocument responceXml = new XmlDocument(); responceXml.LoadXml(soapResult); XmlNodeList appointmentsresponce = responceXml.GetElementsByTagName("basicInvokeResponse"); foreach (XmlNode node in appointmentsresponce[0]) { XmlDocument responceXml2 = new XmlDocument(); string samplexmlfile = Convert.ToString(node.InnerText); responceXml2.LoadXml(samplexmlfile); XmlNodeList appointmentsresponce2 = responceXml2.GetElementsByTagName("create-appointment-response"); foreach (XmlNode node2 in appointmentsresponce2) { XmlElement flightEle = (XmlElement)node2; } – Dileep Jul 16 '18 at 13:33
  • Please check above my exact code,for that code how can i access data – Dileep Jul 16 '18 at 13:36
  • Can you show the a xml file example that you are working with? From the code I can see elements such as "create-appointment-response" that aren't visible on the question – Afonso Jul 16 '18 at 13:40
0

Simple call GetAttribute("AttributeName") on your XmlElement

So:

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")
Mattkwish
  • 753
  • 7
  • 16