<bdo id='yQRym'></bdo><ul id='yQRym'></ul>
    <legend id='yQRym'><style id='yQRym'><dir id='yQRym'><q id='yQRym'></q></dir></style></legend>
      <i id='yQRym'><tr id='yQRym'><dt id='yQRym'><q id='yQRym'><span id='yQRym'><b id='yQRym'><form id='yQRym'><ins id='yQRym'></ins><ul id='yQRym'></ul><sub id='yQRym'></sub></form><legend id='yQRym'></legend><bdo id='yQRym'><pre id='yQRym'><center id='yQRym'></center></pre></bdo></b><th id='yQRym'></th></span></q></dt></tr></i><div id='yQRym'><tfoot id='yQRym'></tfoot><dl id='yQRym'><fieldset id='yQRym'></fieldset></dl></div>
      1. <small id='yQRym'></small><noframes id='yQRym'>

        <tfoot id='yQRym'></tfoot>

        在代码中从 XML 创建 XSD

        时间:2023-06-02

          1. <legend id='Wd9o0'><style id='Wd9o0'><dir id='Wd9o0'><q id='Wd9o0'></q></dir></style></legend>

            • <small id='Wd9o0'></small><noframes id='Wd9o0'>

              <i id='Wd9o0'><tr id='Wd9o0'><dt id='Wd9o0'><q id='Wd9o0'><span id='Wd9o0'><b id='Wd9o0'><form id='Wd9o0'><ins id='Wd9o0'></ins><ul id='Wd9o0'></ul><sub id='Wd9o0'></sub></form><legend id='Wd9o0'></legend><bdo id='Wd9o0'><pre id='Wd9o0'><center id='Wd9o0'></center></pre></bdo></b><th id='Wd9o0'></th></span></q></dt></tr></i><div id='Wd9o0'><tfoot id='Wd9o0'></tfoot><dl id='Wd9o0'><fieldset id='Wd9o0'></fieldset></dl></div>
                <bdo id='Wd9o0'></bdo><ul id='Wd9o0'></ul>

                <tfoot id='Wd9o0'></tfoot>

                  <tbody id='Wd9o0'></tbody>
                1. 本文介绍了在代码中从 XML 创建 XSD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在使用 MSDN 中的这段代码从 XML 创建 XSD

                  I am using this piece of code from MSDN to create an XSD from an XML

                  XmlReader reader = XmlReader.Create("contosoBooks.xml");
                  XmlSchemaSet schemaSet = new XmlSchemaSet();
                  XmlSchemaInference schema = new XmlSchemaInference();
                  
                  schemaSet = schema.InferSchema(reader);
                  
                  foreach (XmlSchema s in schemaSet.Schemas())
                  {
                     textbox.text = s.ToString();
                  }
                  

                  我想根据我的 xml 文件输出 .xsd.当我生成 .xsd 文件时,我得到的唯一内容是:System.Xml.Schema.XmlSchema

                  I want to output the .xsd based on my xml file. When I generate the .xsd file, the only content I get inside it is: System.Xml.Schema.XmlSchema

                  当我使用 Visual Studio 选项生成 XSD 来创建架构时,它会正确显示.但是,我有超过 150 个 xml 文档需要创建 XSD,因此需要一个编程选项.有人可以帮忙吗?

                  When I generate the XSD using Visual Studio option to create Schema, it comes out properly. However, I have over 150 xml docs that I need to create XSD for hence need a programmatic option. Can anyone help?

                  推荐答案

                  这就是你缺少的...而不是简单地执行 s.ToString(),而是这样做:

                  This is what you're missing... instead of simply doing s.ToString(), do this:

                  XmlWriter writer;
                  int count = 0;
                  foreach (XmlSchema s in schemaSet.Schemas())
                  {
                      writer = XmlWriter.Create((count++).ToString() + "_contosobooks.xsd");
                      s.Write(writer);
                      writer.Close();
                      Console.WriteLine("Done " + count);
                  }
                  reader.Close();
                  

                  然后您可以编写适当的逻辑来更优雅地进行读/写,读取许多 xml 文件并创建相应的 xsd 文件等.

                  You can then write proper logic to do the read/write more gracefully, read many xml files and create corresponding xsd files, etc.

                  我从这里获取了 contosobooks.xml:https://code.google.com/p/code4cs/source/browse/trunk/AppCase/dNet/Xml/data/contosoBooks.xml?spec=svn135&r=135

                  I took the contosobooks.xml from here: https://code.google.com/p/code4cs/source/browse/trunk/AppCase/dNet/Xml/data/contosoBooks.xml?spec=svn135&r=135

                  输出 xsd 为:

                  <?xml version="1.0" encoding="utf-8"?>
                  <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.contoso.com/books" xmlns:xs="http://www.w3.org/2001/XMLSchema">
                      <xs:element name="bookstore">
                          <xs:complexType>
                              <xs:sequence>
                                  <xs:element maxOccurs="unbounded" name="book">
                                      <xs:complexType>
                                          <xs:sequence>
                                              <xs:element name="title" type="xs:string" />
                                              <xs:element name="author">
                                                  <xs:complexType>
                                                      <xs:sequence>
                                                          <xs:element minOccurs="0" name="name" type="xs:string" />
                                                          <xs:element minOccurs="0" name="first-name" type="xs:string" />
                                                          <xs:element minOccurs="0" name="last-name" type="xs:string" />
                                                      </xs:sequence>
                                                  </xs:complexType>
                                              </xs:element>
                                              <xs:element name="price" type="xs:decimal" />
                                          </xs:sequence>
                                          <xs:attribute name="genre" type="xs:string" use="required" />
                                          <xs:attribute name="publicationdate" type="xs:date" use="required" />
                                          <xs:attribute name="ISBN" type="xs:string" use="required" />
                                      </xs:complexType>
                                  </xs:element>
                              </xs:sequence>
                          </xs:complexType>
                      </xs:element>
                  </xs:schema>
                  

                  这篇关于在代码中从 XML 创建 XSD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何解析 XSD 以从 &lt;xsd:simpleType&gt; 获取信 下一篇:xsd.exe 生成的 c# 具有数组中的多个元素

                  相关文章

                  最新文章

                    <legend id='I5pzh'><style id='I5pzh'><dir id='I5pzh'><q id='I5pzh'></q></dir></style></legend>
                    1. <tfoot id='I5pzh'></tfoot>

                      <small id='I5pzh'></small><noframes id='I5pzh'>

                      <i id='I5pzh'><tr id='I5pzh'><dt id='I5pzh'><q id='I5pzh'><span id='I5pzh'><b id='I5pzh'><form id='I5pzh'><ins id='I5pzh'></ins><ul id='I5pzh'></ul><sub id='I5pzh'></sub></form><legend id='I5pzh'></legend><bdo id='I5pzh'><pre id='I5pzh'><center id='I5pzh'></center></pre></bdo></b><th id='I5pzh'></th></span></q></dt></tr></i><div id='I5pzh'><tfoot id='I5pzh'></tfoot><dl id='I5pzh'><fieldset id='I5pzh'></fieldset></dl></div>
                      • <bdo id='I5pzh'></bdo><ul id='I5pzh'></ul>