使用XSD文件从Excel导出XML失败问题求助
Hey there! The problem here is that your current XSD doesn't match the XML structure you want to generate—that's exactly why Excel can't create the XML file when you try to export. Let's break this down and fix it.
Your Desired XML Structure
First, let's recap the valid structure you're aiming for (I added a root element since XML requires exactly one root node—this was missing in your example but is mandatory for valid XML):
<Root> <Data> <ID>1</ID> <Number>21</Number> <Number>23</Number> <Number>22</Number> </Data> <Data> <ID>2</ID> <Number>24</Number> <Number>25</Number> </Data> <Data> <ID>3</ID> <Number>26</Number> <Number>26</Number> </Data> </Root>
The Problem with Your Original XSD
Your existing XSD defines a <Root> element that contains multiple <ID> elements (each with an ID attribute and nested <Numbers> elements)—this structure is completely mismatched with your desired <Data>-centric layout. Excel can't map your spreadsheet columns to this incompatible schema, hence the export failure.
Corrected XSD Matching Your Desired Structure
Here's an XSD that perfectly aligns with the XML you want to generate:
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- Root element wrapping all Data nodes --> <xs:element name="Root"> <xs:complexType> <xs:sequence> <xs:element name="Data" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <!-- Single ID value per Data entry --> <xs:element name="ID" type="xs:string"/> <!-- Multiple Number values per Data entry --> <xs:element name="Number" type="xs:string" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
Quick Tips:
- If your Excel columns for
IDandNumberare numeric (not text), swapxs:stringwithxs:intfor stricter type validation. - Always ensure your XML has one single root element—this is a non-negotiable rule for valid XML files.
Next Steps:
- Replace your existing XSD with this corrected version.
- Re-map your Excel columns (ID →
<ID>, Number →<Number>) using Developer mode. - Try exporting XML again—it should work smoothly now!
内容的提问来源于stack exchange,提问作者Calyfs0

