C#.NET序列化 - 如何在输出中包含模式

时间:2010-09-09 19:39:33

标签: .net xml-serialization xsd

我使用XSD.EXE为XML Web服务生成了一个类。我的问题是如何包含架构?

当前XML输出:

<?xml version="1.0" encoding="utf-8"?>
<dsXmlSummary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.tempuri.org/dsXmlSummary.xsd">
  <admin_reports_xmlReports>
    <emailAddress>test@test.com</emailAddress>
    <city>Redding</city>
    <nameLast>Mark</nameLast>
    <nameFirst>Twain</nameFirst>
    <street>123 main</street>
    <state>CT</state>
    <phone />
    <courseNo>316</courseNo>
  </admin_reports_xmlReports>
</dsXmlSummary>

所需的XML输出:

<?xml version="1.0" encoding="utf-8"?>
<dsXmlSummary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.tempuri.org/dsXmlSummary.xsd">
 <xs:schema id="dsXmlSummary" targetNamespace="http://www.tempuri.org/dsXmlSummary.xsd"
    xmlns:mstns="http://www.tempuri.org/dsXmlSummary.xsd" xmlns="http://www.tempuri.org/
dsXmlSummary.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:
schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault=
"qualified">
        <xs:element name="dsXmlSummary" msdata:IsDataSet="true">
            <xs:complexType>
                <xs:choice maxOccurs="unbounded">
                    <xs:element name="admin_reports_xmlReports">
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name="emailAddress" type="xs:string" minOccurs="0"/>
                                <xs:element name="city" type="xs:string" minOccurs="0"/>
                                <xs:element name="nameLast" type="xs:string" minOccurs="0"/>
                                <xs:element name="nameFirst" type="xs:string" minOccurs="0"/>
                                <xs:element name="nameMiddle" type="xs:string" minOccurs="0"/>
                                <xs:element name="street" type="xs:string" minOccurs="0"/>
                                <xs:element name="state" type="xs:string" minOccurs="0"/>
                                <xs:element name="phone" type="xs:string" minOccurs="0"/>
                            </xs:sequence>
                        </xs:complexType>
                    </xs:element>
                </xs:choice>
            </xs:complexType>
        </xs:element>
    </xs:schema>
  <admin_reports_xmlReports>
    <emailAddress>test@test.com</emailAddress>
    <city>Redding</city>
    <nameLast>Mark</nameLast>
    <nameFirst>Twain</nameFirst>
    <street>123 main</street>
    <state>CT</state>
    <phone />
    <courseNo>316</courseNo>
  </admin_reports_xmlReports>
</dsXmlSummary>

我在序列化上找不到任何指定如何在输出中包含它的内容。

this

相关

0 个答案:

没有答案