为什么 linq to xml 不读取 xml 文件?
我正在为 sharepoint 2010 开发 silverlight web 部件。在我的项目中,我已将 xlsx 文件从 sharepoint 服务器下载到本地独立存储。现在,我使用 ICSharpCode.SharpZipLib.Silverlight dll 压缩 xlsx 文件,然后将该压缩文件解压缩到目标文件夹。这一切都是通过编程完成的。当我解压缩文件时,它会在目标文件夹内创建文件夹 _reslx、customXml、docenter code hereProps、xl。 xl 文件夹中有sharedStrings.xml,它是主要的xml 文件。该文件包含原始 xlsx 文件的所有内容。我使用以下代码成功加载了 xml 文件。
xmlDoc = XDocument.Load(readFile);
我没有在加载的 xml 文件中获取 xml 声明。但是我可以看到带有以下句子的 xml 声明。
XDeclaration a = xmlDoc.Declaration;
在“a”中,我得到的值 "{}"
我得到以下 xml加载后的文件。
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="67" uniqueCount="39">
<si>
<t>INVOICE</t>
</si>
<si>
<t>INVOICE #</t>
</si>
<si>
<t>Bill To:</t>
</si>
<si>
<t>DESCRIPTION</t>
</si>
<si>
<t>AMOUNT</t>
</si>
<si>
<t>TOTAL</t>
</si>
<si>
<t>FOR:</t>
</si>
<si>
<t>PBS</t>
</si>
<si>
<t>8108 SE Coconut St.</t>
</si>
<si>
<t>Hobe Sound, FL 33455</t>
</si>
<si>
<t>772-349-6317 Phone 772-675-9100 Fax</t>
</si>
<si>
<t>EIN 20-5268843</t>
</si>
<si>
<t>Provider 693068996</t>
</si>
<si>
<t>Rate</t>
</si>
<si>
<t>Units</t>
</si>
<si>
<t>DATE</t>
</si>
<si>
<t>Michael Nolan Ph.D. BCBA</t>
</si>
<si>
<t>____________________________________________</t>
</si>
<si>
<t>BCBA Date</t>
</si>
<si>
<t>CLIENT:</t>
</si>
<si>
<t>Date:</t>
</si>
<si>
<t>Behavior Assistant- L. Bresson</t>
</si>
<si>
<t>Email:</t>
</si>
<si>
<t>1 Unit = 1 hour</t>
</si>
<si>
<t>TOTALS</t>
</si>
<si>
<t>[email protected]</t>
</si>
<si>
<t>Attn: Cecilia</t>
</si>
<si>
<t>Behavior Assistant- B. Bresson</t>
</si>
<si>
<t>Behaviror Ass't -N Giarratano</t>
</si>
<si>
<t>Signature of Representatives Approval Date</t>
</si>
<si>
<r>
<t xml:space="preserve">Behavior Asst- </t>
</r>
<r>
<rPr>
<sz val="9" />
<rFont val="Arial" />
<family val="2" />
</rPr>
<t>N Giarratano-</t>
</r>
<r>
<rPr>
<sz val="10" />
<rFont val="Arial" />
<family val="2" />
</rPr>
<t>08</t>
</r>
</si>
<si>
<t>Behavior Asst- B. Bresson-08</t>
</si>
<si>
<t>Behavior Asst- L. Bresson-08</t>
</si>
<si>
<t><@Invoice></t>
</si>
<si>
<t><@For></t>
</si>
<si>
<t><@Client></t>
</si>
<si>
<t><@Caregiver></t>
</si>
<si>
<t><@Email,@Address,@City,@State,@Zip></t>
</si>
<si>
<t><@Date></t>
</si>
</sst>
当我查询这个 xml 文件时,我在“eles”中得到的结果是“枚举没有结果”。我正在使用以下查询
var eles = from c in xmlDoc.Descendants("si")
select c;
为什么我的 xml 文件无法正确读取。你能告诉我哪里出错了吗?或者您能给我提供任何可以解决上述问题的链接吗?
I am developing silverlight web part for sharepoint 2010. In my project I have downloaded the xlsx file from the sharepoint server to the local isolated storage. Now I am zipping the xlsx file with the ICSharpCode.SharpZipLib.Silverlight dll and then I am unzipping that zipped file to a target folder. This all is done through programatically. When I unzip the file it creates the folders _reslx, customXml, docenter code hereProps, xl inside the target folder. In the xl folder there is sharedStrings.xml which is the main xml file. This file contains all the contents of the original xlsx file. I am successfully loading the the xml file with the following code.
xmlDoc = XDocument.Load(readFile);
I am not getting the xml declartion in the loaded xml file. However I can see the xml declartion with the following sentence.
XDeclaration a = xmlDoc.Declaration;
In 'a' i am getting the value "{<?xml version="1.0" encoding="UTF-8" standalone="yes"?>}"
I am getting the following xml file after loading.
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="67" uniqueCount="39">
<si>
<t>INVOICE</t>
</si>
<si>
<t>INVOICE #</t>
</si>
<si>
<t>Bill To:</t>
</si>
<si>
<t>DESCRIPTION</t>
</si>
<si>
<t>AMOUNT</t>
</si>
<si>
<t>TOTAL</t>
</si>
<si>
<t>FOR:</t>
</si>
<si>
<t>PBS</t>
</si>
<si>
<t>8108 SE Coconut St.</t>
</si>
<si>
<t>Hobe Sound, FL 33455</t>
</si>
<si>
<t>772-349-6317 Phone 772-675-9100 Fax</t>
</si>
<si>
<t>EIN 20-5268843</t>
</si>
<si>
<t>Provider 693068996</t>
</si>
<si>
<t>Rate</t>
</si>
<si>
<t>Units</t>
</si>
<si>
<t>DATE</t>
</si>
<si>
<t>Michael Nolan Ph.D. BCBA</t>
</si>
<si>
<t>____________________________________________</t>
</si>
<si>
<t>BCBA Date</t>
</si>
<si>
<t>CLIENT:</t>
</si>
<si>
<t>Date:</t>
</si>
<si>
<t>Behavior Assistant- L. Bresson</t>
</si>
<si>
<t>Email:</t>
</si>
<si>
<t>1 Unit = 1 hour</t>
</si>
<si>
<t>TOTALS</t>
</si>
<si>
<t>[email protected]</t>
</si>
<si>
<t>Attn: Cecilia</t>
</si>
<si>
<t>Behavior Assistant- B. Bresson</t>
</si>
<si>
<t>Behaviror Ass't -N Giarratano</t>
</si>
<si>
<t>Signature of Representatives Approval Date</t>
</si>
<si>
<r>
<t xml:space="preserve">Behavior Asst- </t>
</r>
<r>
<rPr>
<sz val="9" />
<rFont val="Arial" />
<family val="2" />
</rPr>
<t>N Giarratano-</t>
</r>
<r>
<rPr>
<sz val="10" />
<rFont val="Arial" />
<family val="2" />
</rPr>
<t>08</t>
</r>
</si>
<si>
<t>Behavior Asst- B. Bresson-08</t>
</si>
<si>
<t>Behavior Asst- L. Bresson-08</t>
</si>
<si>
<t><@Invoice></t>
</si>
<si>
<t><@For></t>
</si>
<si>
<t><@Client></t>
</si>
<si>
<t><@Caregiver></t>
</si>
<si>
<t><@Email,@Address,@City,@State,@Zip></t>
</si>
<si>
<t><@Date></t>
</si>
</sst>
When I am quering on this xml file I am getting the result in 'eles' as "Enumeration yielded no results". I am using the following query
var eles = from c in xmlDoc.Descendants("si")
select c;
Why my xml file is not reading properly. Can you please tell me where I am going wrong ? or can you please provide me any link through which I can resolve the above issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
指定命名空间。
Specify the namespace.