使用svcutil从简单xml文件生成C#类

使用svcutil从简单xml文件生成C#类,c#,xml,C#,Xml,我有以下XML。我正在尝试使用svcutil生成C#类。我知道还有其他工具(如Visual Studio Paste Special和),但我需要了解svcutil是如何生成它的 <?xml version="1.0"?> <ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:voc="urn:hl7-org:v3/voc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tem

我有以下XML。我正在尝试使用svcutil生成C#类。我知道还有其他工具(如Visual Studio Paste Special和),但我需要了解svcutil是如何生成它的

<?xml version="1.0"?>
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:voc="urn:hl7-org:v3/voc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" templateId="2.16.840.1.113883.3.27.1776">
    <title>Gc test Consultation Note</title>
    <effectiveTime value="20000407"/>
    <component>
        <StructuredBody>
            <component>
                <section>
                    <code code="10164-2" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC"/>
                    <title>History of Present Illness</title>
                    <text>Test patient is a 67 year old male referred for further asthma management. Onset of asthma in his 
                <content revised="delete">twenties</content>
                <content revised="insert">teens</content>.
                He was hospitalized twice last year, and already twice this year. He has not been able to be weaned off steroids for the past several months. 
                        </text>
                </section>
            </component>
        </StructuredBody>
    </component>
</ClinicalDocument>


如何使用svcutil从这个XML生成C类?

svcutil
基于SOAP服务契约(或者至少是XML模式)生成类。您得到的是简单的旧XML,而不是SOAP
svcutil
不会为此生成类。如果因为这是服务的一部分而需要查看“svcutil如何生成它”,则至少需要为它提供
ClinicalDocument
的模式,而不是实际的
ClinicalDocument
。请先尝试
xsd.exe
从XML生成xsd。只有在XSD上运行
svcutil
,才能拥有客户端类。@WiktorZychla XSD.exe无法为此生成XSD。你试过了吗?XSD.exe打嗝是因为你有东西。看来XSD.exe工具不喜欢在其内部嵌套同名元素。如果是我,我会手动重命名其中一个组件元素,运行该工具,然后返回并处理生成的XSD(重新命名)。您可能会发现很难(谁知道甚至不可能)在XML模式中描述这一点。顺便说一句,如果您发布XSD.exe错误消息,可能会很好-我没有任何字符了。
   svcutil.exe /target:code /dataContractOnly /serializer:XmlSerializer /importXmlTypes /collectionType:System.Collections.Generic.List`1 hl7sample.xml