0

I want to fetch particular node form XML for that in model I have written below code:

var gp = (from Trans_Mast in r2ge.Transcription_Master where Trans_Mast.Transcription_Id == Trans_ID && Trans_Mast.Entity_Id == Job_ID select Trans_Mast).Distinct();
        foreach (var g in gp)
        {
            p.group = g.Group_xml.ToString();
            XDocument xd = XDocument.Parse(p.group.ToString());

            var names = (xd.Descendants("Group").Where(c => c.Attribute("name").Value.Equals(GroupName))).ToList(); //xml particular data is fetch
            foreach (var item in names)
            {

            }
            data = xd.ToString();
            Transcription_Master Trans_Mast = r2ge.Transcription_Master.First(c => c.Transcription_Id == Trans_ID && c.Entity_Id == Job_ID);
            Int32 TransID = Convert.ToInt32(Trans_ID);
            r2ge.UpdateXml(TransID, data);
        }

from this i get XMl like

<Group name="Front0">
  <Room_type>Front</Room_type>
  <Dimension>Not available</Dimension>
  <Status>PENDING</Status>
  <Notes>None</Notes>
</Group>

Now i want to fetch only status from this xml..how to do that in foreach loop?

  • I have shown code..From whole Xml it fetch only matching groupname part and Now I want to fetch status node form that xml and want to change it..How to get that node @RubenSteins –  Apr 15 '15 at 08:15
  • You show an empty loop. I don't see any code trying to fetch the status node. Why not try to fetch it the same way you got the list of names just above the loop? – Ruben Steins Apr 15 '15 at 08:17
  • Thats what I am asking.. I can not fetch status node using above loop code @RubenSteins –  Apr 15 '15 at 08:21
  • yah I fetch by foreach (var item in names) { item.Element("Status").Value = " "; } and it working –  Apr 15 '15 at 08:28

1 Answers1

0

According to the MSDN-docs, XElement (which I assume is the datatype of your 'item') also has the Descendants method. Why not use that to select the Status?

var status = item.Descendants("Status").FirstOrDefault();

Also, there's the Element method which you can use directly:

var status = item.Element("Status");
Ruben Steins
  • 2,782
  • 4
  • 27
  • 48