4

嗨,我有一个包含字段名称和类型的 Excel,如下例所示。

 ID : INT
 First_Name : String
 Last_Name : String
 Phone number : String

我想根据我的描述生成一个 XSD。

有这个工具吗?

4

2 回答 2

2

Note: there is no solution using just Excel.

This was true in 2013 when the OP asked the question, and is still true now, as far as I can tell.

The answers provided on this page, though they use external tooling, represent the only solutions on the internet at this time, and have since been viewed 13,000 times.

If you or anyone you know have a solution using only Excel to generate XSD, please add it, because this is clearly something that would help many people.


Model the class in code:

public class Something
{
    public int ID { get; set; }
    public string First_Name { get; set; }
    public string Last_Name { get; set; }
    public string Phone_number { get; set; }
}

Save it to a .cs file and then compile it.

and then use xsd.exe to generate the xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Something" nillable="true" type="Something" />
  <xs:complexType name="Something">
    <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="1" name="ID" type="xs:int" />
      <xs:element minOccurs="0" maxOccurs="1" name="First_Name" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" name="Last_Name" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" name="Phone_number" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
</xs:schema>
于 2013-10-08T12:49:41.097 回答
2
  1. 在记事本中,像这样编写新架构:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <record>
       <ID>12345</ID>
       <FirstName>First Name</FirstName>
       <LastName>Last Name</LastName>
       <PhoneNumber>555-555-5555</PhoneNumber>
     </record>
     <record>
       <ID>12346</ID>
       <FirstName>John</FirstName>
       <LastName>Doe</LastName>
       <PhoneNumber>555-555-5555</PhoneNumber>
     </record>
    </data-set>
    
  2. 将文件另存为 schema.xml

  3. 打开你的excel文件。
  4. 在 Developer 选项卡上,打开 XML Source 任务窗格。
  5. 要添加 XML 映射,请单击 XML 映射

在此处输入图像描述

  1. 点击添加
  2. 选择 schema.xml 并单击 OK 两次
  3. 现在只需将 4 个元素从树中拖(映射)到工作表(第 1 行)。图像显示前两个已完成。

在此处输入图像描述

  1. 在 Developer 选项卡上的 XML 组下,单击 Export。
  2. 将文件另存为 data-set.xml 并按 Enter。

结果将如下所示:

在此处输入图像描述

于 2013-10-04T23:23:52.253 回答