Hallo,
ich habe folgende XSD-Datei:
<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSpy v2008 sp1 (http://www.altova.com)-->
<xs:schema xmlns="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2001/XMLSchema-instance">
<xs:complexType name="T_Tender">
<xs:sequence>
<xs:element name="LineNumber" type="xs:string"/>
</xs:sequence>
<xs:attribute name="TenderTypeCode" use="required">
<xs:simpleType>
<xs:restriction base="xs:byte">
<xs:enumeration value="108"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<xs:element name="Tender" type="T_Tender"/>
</xs:schema>
Ich versuche das Schema mit folgendem Code einzulesen:
System.Xml.Schema.XmlSchema mainSchema = System.Xml.Schema.XmlSchema.Read(new System.IO.StringReader(schemaText), new System.Xml.Schema.ValidationEventHandler(ValidationHandler))
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add(mainSchema); //Exception wird ausgelöst
Wenn ich das Schema zum SChemaSet hinzufügen will, wird folgende Exception ausgelöst:> Fehlermeldung:
System.Xml.Schema.XmlSchemaException: Der Zielnamespace einer lokalen oder globalen Attributsdeklaration darf nicht mit
> übereinstimmen.
bei System.Xml.Schema.XmlSchemaSet.InternalValidationCallback(Object sender, ValidationEventArgs e)
bei System.Xml.Schema.BaseProcessor.SendValidationEvent(XmlSchemaException e, XmlSeverityType severity)
bei System.Xml.Schema.Preprocessor.PreprocessAttributeContent(XmlSchemaAttribute attribute)
bei System.Xml.Schema.Preprocessor.PreprocessLocalAttribute(XmlSchemaAttribute attribute)
bei System.Xml.Schema.Preprocessor.PreprocessAttributes(XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, XmlSchemaObject parent)
bei System.Xml.Schema.Preprocessor.PreprocessComplexType(XmlSchemaComplexType complexType, Boolean local)
bei System.Xml.Schema.Preprocessor.Preprocess(XmlSchema schema, String targetNamespace, ArrayList imports)
bei System.Xml.Schema.Preprocessor.Execute(XmlSchema schema, String targetNamespace, Boolean loadExternals)
bei System.Xml.Schema.XmlSchemaSet.PreprocessSchema(XmlSchema& schema, String targetNamespace)
bei System.Xml.Schema.XmlSchemaSet.Add(String targetNamespace, XmlSchema schema)
bei System.Xml.Schema.XmlSchemaSet.Add(XmlSchema schema)
Ich weiß aber nicht warum, bzw. wie ich das Attribut TenderTypeCode definieren muss, damit es funktioniert.
Mit TenderTypeCode hat die Fehlermeldung nichts zu tun. Eigentlich steht in der Fehlermeldung genau, was das Problem ist:
Der Zielnamespace einer lokalen oder globalen Attributsdeklaration darf nicht mit
> übereinstimmen.
Zielnamespace auf englisch = targetNamespace
Diese Erkenntnis noch auf folgende Zeile anwenden
<xs:schema xmlns="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2001/XMLSchema-instance">
Grüße
Lynix
"It is not wise to be wise" - Sun Tzu
Hallo Lynix,
ja, das es am TargetNamespace liegt habe ich schon gesehen.
TenderTypeCode ist das Attribut, wodurch die Exception ausgelöst.
Meine Frage ist, wie ich das Attribut definieren muss, damit ich als targetNamespace "http://www.w3.org/2001/XMLSchema-instance" benutzen kann.
Was passiert denn, wenn du einen anderen Namespace wählst?
Sowas wie expample.org?
Der Vorteil der Klugheit liegt darin, dass man sich dumm stellen kann - umgekehrt ist das schon schwieriger (K. Tucholsky)
Das Problem mit Internet-Zitaten ist, dass sie oftmals zu unrecht als authentisch angenommen werden. (K. Adenauer)
Ich habe jetzt den targetNamespace auf example.org gesetzt.
Wenn ich das SchemaSet jetzt kompiliere ( schemaSet.Compile();), erhalte ich einen Validierungsfehler:
"Der Typ 'http://www.w3.org/2001/XMLSchema-instance:T_Tender' ist nicht deklariert. Line[16] Position[6]"