2011-02-04 5 views
1

Je XSD comme ci-dessous:Erreur Visual Studio XSD Tool?

<?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> 

Lorsque j'ai couru l'outil XSD avec commande ci-dessous dans VS 2008 invite de commande: xsd/classes/langue: vb test.xsd

Je reçois ci-dessous le code

'------------------------------------------------------------------------------ 
' <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 

Lorsque l'élément que j'ai spécifié est CurrentRefSpecified. Pourquoi est-il affiché comme CurrentRefSpecified1 dans la classe générée? Est-ce un problème avec XSD ou mon problème?

Quelqu'un peut-il répondre rapidement à cette question?

Ce appending se passe automatiquement lorsque nous avons le nom de l'élément dit « xyzspecified » .. la propriété dans le fichier de classe est défini comme xyzspecified1 ...

Répondre

1

Je ne sais pas pour vous, mais voici mon hypothèse: pour certains champs du XML, s'ils peuvent être omis ou spécifiés, xsd.exe génère un champ correspondant appelé (yourfieldname)Specified pour indiquer si une valeur potentiellement nillable/manquante a été spécifiée ou non.

Maintenant, ce n'est pas le cas dans votre échantillon comme il est maintenant - mais si vous changez votre XSD pour rendre votre champ CurrentRef ou minOccurs=0 dessus, alors l'outil xsd.exe devrait créer un CurrentRefSpecified champ d'assistance pour cela, et cela serait en conflit avec votre champ déjà existant dans le XSD.

Je devine que l'outil xsd va "renommer" votre champ CurrentRefSpecified en CurrentRefSpecified1, afin d'éviter tout conflit potentiel (futur).

+0

Merci pour votre réponse rapide marc_s – Sathish