简体   繁体   中英

read xml in asp.net c#

I am having issues with accessing the last node in this xml document the document follows the format of

   <?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">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Created>2016-11-29T14:40:38Z</Created>
<Version>14.00</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<RemovePersonalInformation/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>8748</WindowHeight>
<WindowWidth>19428</WindowWidth>
<WindowTopX>0</WindowTopX>
<WindowTopY>108</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s62">
<NumberFormat ss:Format="Short Date"/>
</Style>
<Style ss:ID="s63">
<NumberFormat ss:Format="Fixed"/>
</Style>
<Style ss:ID="s64">
<NumberFormat ss:Format="0"/>
</Style>
</Styles>
<Worksheet ss:Name="xml File">
<Table ss:ExpandedColumnCount="7" ss:ExpandedRowCount="771" x:FullColumns="1" x:FullRows="1" ss:DefaultRowHeight="14.55">
<Column ss:Width="57"/>
<Column ss:Width="56.4" ss:Span="1"/>
<Column ss:Index="4" ss:Width="50.4" ss:Span="3"/>
<Row ss:AutoFitHeight="0">
<Cell>
<Data ss:Type="String">Date</Data>
</Cell>
<Cell>
<Data ss:Type="String">ULSP</Data>
</Cell>
<Cell>
<Data ss:Type="String">ULSD</Data>
</Cell>
<Cell>
<Data ss:Type="String">ULSP</Data>
</Cell>
<Cell>
<Data ss:Type="String">ULSD</Data>
</Cell>
<Cell>
<Data ss:Type="String">ULSP</Data>
</Cell>
<Cell>
<Data ss:Type="String">ULSD</Data>
</Cell>
</Row>

I have tried using the following and have had problems. reading the lastnode element simply returns nearly all of the xml document

string id = "2003-06-16T00:00:00.000"; // id to be selected

    XElement Contact = (from xml2 in doc.Descendants("cell")
                        where xml2.Element("data").Value == id
                        select xml2).FirstOrDefault();

Through Bad Idea But Split Will Work Like A Charm Here ...

//data is your xml data in plain text format without modification
String sp1 = data.Split(new string[] { "<Created>" }, StringSplitOptions.None)[1];
String sp2 = sp1.Split(new string[] { "</Created>" }, StringSplitOptions.None)[0];
//sp2 is the required string you want which has value 2003-06-16T00:00:00.000

Hope This Helps ! Cheers!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM