xml 如何将 XSD 文件转换为 XLS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11920649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:38:58  来源:igfitidea点击:

How to convert XSD file to XLS

xmlexcelxsd

提问by praveen kumar

I have a XSD file and I need to convert that to MS Excel file. The XSD is below.

我有一个 XSD 文件,我需要将其转换为 MS Excel 文件。XSD 如下。

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="shiporder">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="orderperson" type="xs:string"/>
      <xs:element name="shipto">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="name" type="xs:string"/>
            <xs:element name="address" type="xs:string"/>
            <xs:element name="city" type="xs:string"/>
            <xs:element name="country" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="item" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="title" type="xs:string"/>
            <xs:element name="note" type="xs:string" minOccurs="0"/>
            <xs:element name="quantity" type="xs:positiveInteger"/>
            <xs:element name="price" type="xs:decimal"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="orderid" type="xs:string" use="required"/>
  </xs:complexType>
</xs:element>

</xs:schema>

Pls help me, I really don't know how and where to start.

请帮助我,我真的不知道如何以及从哪里开始。

回答by Petru Gardea

This answer is equally for you as well as @Alex, @Michael and @forty-two. I am illustrating it using Excel 2010, so if you're on another version, I'll leave it up to you to make the necessary adjustments.

这个答案同样适用于您以及@Alex、@Michael 和@forty-2。我将使用 Excel 2010 对其进行说明,因此如果您使用的是其他版本,我会让您自行进行必要的调整。

First thing, make sure the developer tab shows (Click the File tab, Options).

首先,确保开发人员选项卡显示(单击文件选项卡,选项)。

Excel 2010 options for Developer tab

开发人员选项卡的 Excel 2010 选项

You now have to create an XML source from your XSD: click the Developer tab; in the XML group, toggle Source button to show the Xml Source task pane; then click the XML Maps button.

您现在必须从 XSD 创建一个 XML 源:单击 Developer 选项卡;在 XML 组中,切换 Source 按钮以显示 Xml Source 任务窗格;然后单击 XML Maps 按钮。

Excel showing key UI elements for creating an XML map

Excel 显示用于创建 XML 映射的关键 UI 元素

Click Add button at the prompt; point to the XSD file; then click OK to go back to the main screen.

出现提示时点击添加按钮;指向XSD文件;然后单击“确定”返回主屏幕。

Excel showing XSD loaded in an XML map

显示在 XML 映射中加载的 XSD 的 Excel

Then you can drag and drop your shipOrder to a cell in a worksheet, to anchor the generated mapped table.

然后,您可以将shipOrder 拖放到工作表中的单元格中,以锚定生成的映射表。

Excel showing mapped XSD

Excel showing mapped XSD

Next, you may use Import to get your XML data into the spreadsheet, and Export to get it out. There are a couple of additional things to pay attention to; read this article on Microsoft's site; pay particular attention to the issues with exporting XML data (error XML maps in my workbook are not exportable). This is because of the 1 to many cardinality between shiporder and item. You can try to handle it using mapped ranges - I'll leave this all up to you. The best would be for you to read the online help for the XML developer section...

接下来,您可以使用 Import 将 XML 数据导入电子表格,然后使用 Export 将其导出。还有一些额外的事情需要注意;在微软网站上阅读这篇文章;特别注意导出 XML 数据的问题(我的工作簿中的错误 XML 映射不可导出)。这是因为 Shiporder 和 item 之间的基数是 1 对多。您可以尝试使用映射范围来处理它 - 这一切都由您决定。最好是让您阅读 XML 开发人员部分的在线帮助...

回答by Ashwath Padmashali

Go to MS Excel-> File-> Open. Select the xsd file.

MS Excel-> File-> Open。选择 xsd 文件。

You will be prompted on how you would like to open the file. You can select the option 'As an XML table'. Save the file in excel format.

系统将提示您希望如何打开文件。您可以选择“作为 XML 表”选项。以excel格式保存文件。

回答by XN16

You could save the file as an XML file and then open it in Excel and open as a 'Read-only workbook' when prompted. However it won't be in a nice format, but at least all the data (along with the XML paths as columns) will be there.

您可以将文件另存为 XML 文件,然后在 Excel 中打开它,并在出现提示时作为“只读工作簿”打开。然而,它的格式不会很好,但至少所有数据(以及作为列的 XML 路径)都会在那里。

You can then edit the data as you require. Anything else will require some processing.

然后,您可以根据需要编辑数据。其他任何事情都需要一些处理。

回答by Michael Kay

Select the whole text of the XSD in a text editor, copy it to the clipboard, click on a cell in an Excel spreadsheet, and do a Paste. Your XSD data will now be in your spreadsheet.

在文本编辑器中选择 XSD 的整个文本,将其复制到剪贴板,单击 Excel 电子表格中的单元格,然后执行粘贴。您的 XSD 数据现在将在您的电子表格中。

It won't be in a very useful format, but you haven't told us what you want the spreadsheet to look like, and I find it hard to imagine a format that wouldbe useful.

这不会是一个非常有用的格式,但是你有没有告诉我们你想要的电子表格的样子,我很难想象,一个格式是有益的。