首页 > 学院 > 开发设计 > 正文

如何引用XML文件生成C#类

2019-11-17 03:09:01
字体:
来源:转载
供稿:网友

如何引用xml文件生成C#类

目录

XSD File Generate Class File Simply. 1

Why use XSD file to create C# classes?... 2

How to convert XML file to XSD file?. 2

How to create C# file by XSD file?. 4

What is xsd command params?. 8

Reference. 11

Why use XSD file to create C# classes?

当应用场景是这样的:

1. 需要定义大量的自定义格式的XML协议,供通讯双方使用,本文基于内部接口测试工具的测试协议格式。

2. 减少中间依赖关系,类依赖于XML协议的格式,而非用CS文件序列化XML文件。

How to convert XML file to XSD file?

准备一个支持W3C标准的XML文件(必须有文件头<?xml version="1.0" encoding="utf-8"?>)

<?xml version="1.0" encoding="utf-8" ?><PRotobuftest>         <head>                   <version>1.0.0</version>                   <description>Bocode protobuf test protocol</description>         </head>         <transaction>                   <name>Transaction 01</name>                   <items>                            <item>                                     <name>Functional Test 01</name>                                     <description>Test protobuf demo</description>                                      <testinput>                                               <code>4002</code>                                     </testinput>                                     <testparams>                                                <usepretest>false</usepretest>                                                                           <keystring>                                                        <key>10005</key>                                                        <value>100</value>                                                        <pindex>0</pindex>                                               </keystring>                                                                  <keybytes>                                                        <key>10007</key>                                                        <value>12jkjk123jk12312k312k3k1221k3jk21123213k3k13k1</value>                                                        <pindex>0</pindex>                                               </keybytes>                                                                           <keylist>                                                        <keystring>                                                                 <key>30002</key>                                                                                    <value>0</value>                                                                 <pindex>0</pindex>                                                        </keystring>                                                        <keystring>                                                                 <key>30002</key>                                                                 <value>10</value>                                                                 <pindex>0</pindex>                                                        </keystring>                                                        <keystring>                                                                 <key>30002</key>                                                                 <value>10</value>                                                                 <pindex>0</pindex>                                                        </keystring>                                               </keylist>                                               </testparams>                                     <testoutput>                                               <resultcode>0</resultcode>                                      </testoutput>                            </item>                             <item>                                     <name>Functional Test 02</name>                                     <description>Test protobuf demo</description>                                     <testinput>                                               <code >4002</code>                                     </testinput>                                     <testparams>                                                <keystring>                                                        <key>10005</key>                                                        <value>100</value>                                               </keystring>                                               <keybytes>                                                        <key>10007</key>                                                        <value>12jkjk123jk12312k312k3k1221k3jk21123213k3k13k1</value>                                               </keybytes>                                               <keylist>                                                        <keystring>                                                                 <key>30002</key>                                                                 <value>0</value>                                                        </keystring>                                                        <keystring>                                                                 <key>30002</key>                                                                 <value>10</value>                                                        </keystring>                                                        <keystring>                                                                 <key>30002</key>                                                                 <value>10</value>                                                        </keystring>                                               </keylist>                                     </testparams>                                     <testoutput>                                               <resultcode>0</resultcode>                                      </testoutput>                            </item>                    </items>         </transaction></protobuftest>
View Code

以文件方式保存在XXX路径下,并启动VS2012 ARM Cross Tools Command Prompt

之后在XXX目录下即生成ProtobufTest_Demo.xsd文件

How to create C# file by XSD file?

首先准备一个xsd文件,保存在XXX路径,命名为ProtobufTest_Demo.xsd

<?xml version="1.0" encoding="utf-8"?><xs:schema id="protobuftest" xmlns="" xmlns:xs="http://www.w3.
上一篇:C++的性能C#的产能?!

下一篇:C#特性杂谈

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表