如何创建xsd来验证excel文件 [英] how to create xsd to validate excel file
问题描述
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" ;>我的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安培;曲ot; maxOccurs =& quot; 1& quot; /& gt;
& lt; xs:element name =& quot; ID_GRUPPO& quot;类型=安培; QUOT; XS:小数&安培; QUOT;的minOccurs =安培; QUOT 0安培; QUOT; maxOccurs =& quot; 1& quot; /& gt;
等等
你能帮我发一个代码示例吗?从xsd验证xls / xlsx罚款?提前谢谢< / pre>
Excel(从2007及更高版本开始)使用非典型的XML文件。请参阅 OpenXML标准 [ ^ ]。您不能以这种方式验证Excel文件。
旧版本的MS Excel不支持OpenXML标准。
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
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="UserSettings">
<xs:complexType>
<xs:sequence>
<xs:element name="ID_UTENTE" type="xs:decimal" minOccurs="1" maxOccurs="1"/>
<xs:element name="ID_GRUPPO" type="xs:decimal" minOccurs="0" maxOccurs="1"/>
etc etc
Can you help me and post a code example to validate xls /xlsx fine from an xsd? thanks in advance</pre>
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.
这篇关于如何创建xsd来验证excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!