XML : Parse xml using Linq to xml when there's no tag name

I have xml. I'm retrieving information using this code:

   XNamespace ns = "urn:schemas-microsoft-com:office:excel";              var xdoc = XDocument.Load(@"path");                IEnumerable<string> ss = xdoc.Descendants(ns + "Crn")                                           .Elements(ns + "Text")                                           .Select(x => (string)x);                      using (System.IO.StreamWriter file =              new System.IO.StreamWriter(@"path", true))              {                  foreach (var x in ss)                  {                      file.WriteLine(x);                  }              }    

But I want to retrieve only last - 1 tag text. I've added there text "this text". How can I do that? If I'll add .LastOrDefault() after .Element It throws an error..

And here's my XML

  <?xml version="1.0"?>  <?mso-application progid="Excel.Sheet"?>  <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"   xmlns:o="urn:schemas-microsoft-com:office:office"   xmlns:x="urn:schemas-microsoft-com:office:excel"   xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"   xmlns:html="http://www.w3.org/TR/REC-html40">  <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">  <SupBook>  <Xct>  <Crn>            <Row>9</Row>            <ColFirst>1</ColFirst>            <ColLast>3</ColLast>            <Text>02</Text>            <Text>this text</Text>            <Text>asd</Text>          </Crn>          <Crn>            <Row>10</Row>            <ColFirst>1</ColFirst>            <ColLast>3</ColLast>            <Number>25</Number>            <Text>this text</Text>            <Text>asd</Text>          </Crn>          <Crn>            <Row>11</Row>            <ColFirst>1</ColFirst>            <ColLast>3</ColLast>            <Number>62</Number>            <Text>this text</Text>            <Text>asd</Text>          </Crn>   </Xct>      </SupBook>    </ExcelWorkbook>  </Workbook>    

I can't change that xml file. I know there must be column names instead of text tag but it's not written by me

No comments:

Post a Comment