簡體   English   中英

在ASP.NET C#中讀取XML

[英]read xml in asp.net c#

我在訪問此xml文檔中的最后一個節點時遇到問題,該文檔遵循以下格式:

   <?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>

我嘗試使用以下方法,但遇到了問題。 讀取lastnode元素只會返回幾乎所有的xml文檔

字符串ID =“ 2003-06-16T00:00:00.000”; //要選擇的ID

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

通過壞主意,但拆分將在這里像魅力一樣工作...

//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

希望這可以幫助 ! 干杯!!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM