2011-02-04 123 views
1

我有XSD如下:Visual Studio XSD工具錯誤?

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="Test" 
    targetNamespace="http://tempuri.org/Test.xsd" 
    elementFormDefault="qualified" 
    xmlns="http://tempuri.org/Test.xsd" 
    xmlns:mstns="http://tempuri.org/Test.xsd" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
> 
    <xs:complexType name="TestCurrency"> 
     <xs:sequence> 
      <xs:element name="CurrencyRef" minOccurs="1" maxOccurs="1" type="xs:int"/> 
      <xs:element name="CurrentRefSpecified" minOccurs="1" maxOccurs="1" type="xs:int"/> 
     </xs:sequence> 
    </xs:complexType> 

    <xs:element name="Currency" type="TestCurrency"/> 

</xs:schema> 

當我在VS跑了XSD工具下面的命令2008年命令提示符: XSD /班/語言:VB test.xsd

我得到下面的代碼

'------------------------------------------------------------------------------ 
' <auto-generated> 
'  This code was generated by a tool. 
'  Runtime Version:2.0.50727.3615 
' 
'  Changes to this file may cause incorrect behavior and will be lost if 
'  the code is regenerated. 
' </auto-generated> 
'------------------------------------------------------------------------------ 

Option Strict Off 
Option Explicit On 

Imports System.Xml.Serialization 

' 
'This source code was auto-generated by xsd, Version=2.0.50727.3038. 
' 

'''<remarks/> 
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038"), _ 
System.SerializableAttribute(), _ 
System.Diagnostics.DebuggerStepThroughAttribute(), _ 
System.ComponentModel.DesignerCategoryAttribute("code"), _ 
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://tempuri.org/Test.xsd"), _ 
System.Xml.Serialization.XmlRootAttribute("Currency", [Namespace]:="http://tempuri.org/Test.xsd", IsNullable:=false)> _ 
Partial Public Class TestCurrency 

    Private currencyRefField As Integer 

    Private currentRefSpecified1Field As Integer 

    '''<remarks/> 
    Public Property CurrencyRef() As Integer 
     Get 
      Return Me.currencyRefField 
     End Get 
     Set 
      Me.currencyRefField = value 
     End Set 
    End Property 

    '''<remarks/> 
    <System.Xml.Serialization.XmlElementAttribute("CurrentRefSpecified")> _ 
    Public Property CurrentRefSpecified1() As Integer 
     Get 
      Return Me.currentRefSpecified1Field 
     End Get 
     Set 
      Me.currentRefSpecified1Field = value 
     End Set 
    End Property 
End Class 

當我指定的元素是CurrentRefSpecified。爲什麼它在生成的類中顯示爲CurrentRefSpecified1?它是否與XSD或我的問題有關?

任何人都可以快速回答這個問題嗎?

,當我們有元素名稱說這追加自動發生「xyzspecified」 ..在類文件的屬性設置爲xyzspecified1 ...

回答

1

我不知道肯定做,但這裏是我的假設:對於XML中的某些字段,如果可以省略或指定它們,xsd.exe將生成一個名爲(yourfieldname)Specified的相應字段,用於指示是否實際指定了可能的可填寫/缺失值。

現在,這是不是你的樣品的情況下的任何地方,因爲它現在是 - 但如果你會改變你的XSD使你的領域CurrentRef是的nillable還是有它minOccurs=0,那麼xsd.exe工具將必須創建一個CurrentRefSpecified它的助手字段,這將與XSD中已經存在的字段衝突。

我猜測爲了避免任何潛在的(未來)衝突,xsd工具會將您的字段CurrentRefSpecified重命名爲CurrentRefSpecified1

+0

感謝您的快速回復marc_s – Sathish 2011-02-04 08:11:19