2017-02-10 3 views
1

In XML-Schema, wie definiere ich eine ComplexType, die wie folgt rendert?XML-Element mit Attribut und String-Inhalt

<ValidationError code="X501">I love cats!</ValidationError> 

Wenn ich die folgenden meine Werkzeuge versuchen * werden sagen, es ist nicht gültig

 <xsd:complexType name="ValidationErrorType"> 
      <xsd:attribute name="code" type="xsd:string"></xsd:attribute> 
      <xsd:simpleContent> 
       <xsd:extension base="xs:string"/> 
      </xsd:simpleContent> 
     </xsd:complexType> 

Werkzeuge ich verwende, sind Altova XMLSpy für die visuelle Bearbeitung und wsdl2java Klassen

-Update zu generieren: Ich habe another flavour versucht

 <xsd:complexType name="ValidationErrorType"> 
      <xsd:simpleContent> 
       <xsd:extension base="xs:string"> 
        <xsd:attribute name="code" type="xsd:string" /> 
       </xsd:extension> 
      </xsd:simpleContent> 
     </xsd:complexType> 

sagte Altova Invalid XML schema: 'Value 'xs:string' is not allowed for attribute 'base'.'

Antwort

1

Okay, habe ich gelernt, die Lektion

  1. Attribute kann ein simpleContent aber Muss im extension
  2. ich den xsd Präfix in meinem zweiten Beispiel vertippt erscheint erstrecken, die
  3. fast richtig war

Die korrekte Form ist

 <xsd:complexType name="ValidationErrorType"> 
      <xsd:simpleContent> 
       <xsd:extension base="xsd:string"> 
        <xsd:attribute name="code" type="xsd:string" /> 
       </xsd:extension> 
      </xsd:simpleContent> 
     </xsd:complexType> 
Verwandte Themen