zoukankan      html  css  js  c++  java
  • svcutil 生成代理类时的问题

    如果有这个的xsd, group内嵌choice的结构:

    <xs:complexType name="CreateType">
            <xs:sequence>
                   <xs:group ref="NameChoicesGroup" />
                   <xs:element name="Info" type="InfoType" />
            </xs:sequence>
    </xs:complexType>

    <xs:group name="NameChoicesGroup">
            <xs:choice>
                    <xs:element name="NameID" type="IDType"/>
                    <xs:element name="Name" type="xs:string"/>
            </xs:choice>
    </xs:group>

    使用svcutil 生成后的结果是:

    public class CreateType

    {

      int NameID

          string Name

    }

    因为是choice 类型,这个结果显然不能表示choice的特点,bug?

    解决问题:

    生成前,使用xslt 把所有的group替换成实际的内容, 生成结果:

    public class CreateType

    {

        [System.Xml.Serialization.XmlElementAttribute("NameID", typeof(uint), Order = 0)]

        [System.Xml.Serialization.XmlElementAttribute("Name", typeof(string), Order = 0)]

        [System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")] 

         object Name {...}

    }

    xslt:

    <xsl:stylesheetversion="1.0" xmlns:xsl=http://www.w3.org/1999/XSL/Transform" xmlns:xs=http://www.w3.org/2001/XMLSchema>

    <xsl:outputmethod="xml"indent="yes"/>

    <xsl:keyname="Groups"match="xs:group[@name='NameChoicesGroup']"use="@name"/>

     <xsl:templatematch="xs:group[@ref='NameChoicesGroup']">

    <xsl:comment> 

    Begin

    <xsl:value-ofselect="@ref"/>

    </xsl:comment><xsl:variablename="Temp"select="key('Groups', 'NameChoicesGroup')"/>

    <xsl:copy-ofselect="$Temp/xs:choice"/>

    <xsl:comment> 

     End

    <xsl:value-ofselect="@ref"/>

    </xsl:comment>

    </xsl:template>

    <xsl:templatematch="@*|node()">

    <xsl:copy>

    <xsl:apply-templatesselect="@*|node()" />

    </xsl:copy>

    </xsl:template>

    </xsl:stylesheet>

  • 相关阅读:
    如何去除ecshop标题和网站底部的Powered by ECShop
    ecshop标签
    安装Wamp后 Apache无法启动的解决方法
    wamp5中的apache不能启动,80端口被占用
    iOS UI-AlertView(警示框)和ActionSheet(选择框、操作表单)
    iOS UI-三种简单的动画设置
    iOS UI-IOS开发中Xcode的一些使用技巧
    iOS UI-九宫格
    iOS开发-开发文档安装
    iOS UI-创建空项目
  • 原文地址:https://www.cnblogs.com/DataFlow/p/4187286.html
Copyright © 2011-2022 走看看