使用C#将XSD文件转换为XML文件 [英] Converting XSD File to XML File using C#

查看:110
本文介绍了使用C#将XSD文件转换为XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试使用c#代码将XSD文件转换为XML文件。我有以下Xsd文件。任何人都可以帮我如何将其转换为xml文件.....







Hi,

I am trying to convert XSD file to XML file using c# code. I am having the Xsd file as following. Can anybody help me how to convert it to xml file.....



<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:simpleType name="GUID">
    <xsd:annotation>
      <xsd:documentation xml:lang="en"> The representation of a GUID, generally the id of an element. </xsd:documentation>
    </xsd:annotation>
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="\{[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\}" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:element name="User">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="Id" type="GUID" />
        <xsd:element name="EntityName" type="xsd:string" />
        <xsd:element name="Name" type="xsd:string" />
        <xsd:element name="Description" type="xsd:string" />
        <xsd:element name="Role" type="GUID" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>







提前致谢。




Thanks in advance.

推荐答案

有一个工具XSD.exe,您可以下载并使用它将xsd文件转换为xml或.cs类文件和其他类型。可在MSDN上找到: XML架构定义工具(Xsd.exe) [ ^ ]
There is a tool XSD.exe which you can download and use it to convert your xsd file to xml or .cs class file and other types. It is available at MSDN: XML Schema Definition Tool (Xsd.exe)[^]


您可以从数据集中获取和编写xml,查看 MSDN [ ^ ]有关get和write方法的代码示例。
You can get and write the xml from your dataset, check MSDN[^] for code examples on the get and write methods.


xsd文件描述了如何以XML格式显示数据但是xsd不包含任何数据。



要编写XML文件,需要一些与xsd项匹配的数据。然后就像上面那样很简单。
An xsd file describes HOW your data is to be presented in XML but xsd does NOT contain any data.

To write an XML file, you need some data that matches the xsd items. Then it's pretty easy as above.


这篇关于使用C#将XSD文件转换为XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆