Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
good morning, i am in a win application in c# language. i have to read a excel file (both xls and xlsx) and i would validate it with an xsd file but i wrong something because i get an error: data at the root level is invalid. Line 1, position 1 if i use the same xsd with corrispondent xml file this work correctly so shoul be a problem in my excel file or in a code to validate my excel file. i have use this code:
XmlReaderSettings booksSettings = new XmlReaderSettings();
booksSettings.Schemas.Add("http://www.w3.org7XMLSchema",XMLImportUsers.xsd");
booksSettings.ValidationType = ValidationType.Schema;
XmlReader books = XmlReader.Create(@"D:\test.xml",booksSettings);

while (books.Read()) { }

<pre lang="xml">my xsd

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
&lt;xs:element name=&quot;UserSettings&quot;&gt;
&lt;xs:complexType&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=&quot;ID_UTENTE&quot; type=&quot;xs:decimal&quot; minOccurs=&quot;1&quot; maxOccurs=&quot;1&quot;/&gt;
&lt;xs:element name=&quot;ID_GRUPPO&quot; type=&quot;xs:decimal&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;1&quot;/&gt;
etc etc

Can you help me and post a code example to validate xls /xlsx fine from an xsd? thanks in advance</pre>
Posted

1 solution

Excel (starting from 2007 and higher) uses non-typical XML file. See OpenXML standard[^]. You can't validate Excel files this way.

Older version of MS Excel does not support OpenXML standard.
 
Share this answer
 
Comments
Member 10846480 9-Oct-14 9:15am    
i'm sorry probably i am not able to clarify my problem.
i have to validate my excel file using c# from an xsd.
i have also tryied to generate xml file save as my file excel like xml file and then by visual studio generate xsd but in this case visual studio creates 3 xsd and i'm not able to manage it.
i should understand why my excel file give me error , instead his corrispondent xml file works fine.

thanks in advance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900