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

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

        以编程方式从 XML Schema 生成测试 XML

        时间:2023-06-04
              <bdo id='pXNnI'></bdo><ul id='pXNnI'></ul>
              <legend id='pXNnI'><style id='pXNnI'><dir id='pXNnI'><q id='pXNnI'></q></dir></style></legend>
            • <small id='pXNnI'></small><noframes id='pXNnI'>

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

                  <tfoot id='pXNnI'></tfoot>
                  本文介绍了以编程方式从 XML Schema 生成测试 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我现在已经搜索了一些,但我无法找到以编程方式从 XML 模式自动生成数据的方法.假设我有这个 XML 模式:

                  I have searched for a bit now, but i'm not able to find a way to autogenerate data from a XML Schema programmatically. Lets say I have this XML schema:

                  <xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" name ="Persons">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="Person">
                          <xs:complexType>
                            <xs:sequence>
                              <xs:element name="FirstName" type="xs:string" />
                              <xs:element name="LastName" type="xs:string" />
                            </xs:sequence>
                          </xs:complexType>
                        </xs:element>
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element> 
                  

                  我可以使用 VS 函数生成示例 XML"由此创建一个 XML
                  有没有办法以编程方式做到这一点?

                  I am able to create a XML from this using the VS function "Generate Sample XML"
                  Is there a way to do this programmatically?

                  指定.我不想自己创建所有对象并以编程方式插入数据.我希望它能够像 VS 中的生成示例 XML"一样自动创建对象和属性.这样做的原因是我想更改 XSD 而不必对 xml 样本生成做任何事情.

                  To specify. I do not want to create all the objects and insert data programmatically myself. I would like for it to create the objects and attributes automatically just like the "Generate Sample XML" in VS. The reason for this is that i would like to change the XSD without having to do anything about xml sample generation.

                  推荐答案

                  经过一番搜索.我找到了一个实现 xml 示例生成器的 项目.我创建了一个测试解决方案并导入了这些类.然后我删除了 XmlGen.cs 文件并创建了我自己的 main 方法.输出将基于根元素.

                  after doing some searching. I have found a project that have implemented a xml sample generator. I created a test solution and imported the classes. Then i deleted the XmlGen.cs file and created my own main method. The output will be based on the root element.

                  public static void Main(string[] args)
                          {
                              using (var stream = new MemoryStream(File.ReadAllBytes("schema.xsd")))
                              {
                                  var schema = XmlSchema.Read(XmlReader.Create(stream ), null);
                                  var gen = new XmlSampleGenerator(schema, new XmlQualifiedName("rootElement"));
                                  gen.WriteXml(XmlWriter.Create(@"c:	empautogen.xml"));
                                  Console.WriteLine("Autogenerated file is here : c:	empautogen.xml");
                              }            
                          }
                  

                  这篇关于以编程方式从 XML Schema 生成测试 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将 XML 读入与其 xsd 匹配的类/类 下一篇:验证 xml 节点,而不是整个文档

                  相关文章

                  最新文章

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

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

                        <bdo id='cKaRM'></bdo><ul id='cKaRM'></ul>

                      <tfoot id='cKaRM'></tfoot>