Mehrere XSDs und mehrere Namensräume in einer XML unterbringen?

sylo

Bekanntes Mitglied
hi zusammen

ich versuche gerade das Beispiel auf folgender Seite nachzuvollziehen:

XML Schemas: Best Practices

Ein kurzer Überblick:
Ich habe drei Schema-Dateien: Product.xsd, Person.xsd und Company.xsd. Diese werden mit der import-Funktion verkoppelt.

[XML]<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.product.org"
xmlns="http://www.product.org"
elementFormDefault="unqualified">
<xsd:complexType name="ProductType">
<xsd:sequence>
<xsd:element name="Type" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>[/XML]

[XML]<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.person.org"
xmlns="http://www.person.org"
elementFormDefault="unqualified">
<xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="SSN" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>[/XML]

[XML]<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.company.org"
xmlns="http://www.company.org"
elementFormDefault="unqualified"
xmlns:per="http://www.person.org"
xmlns:pro="http://www.product.org">
<xsd:import namespace="http://www.person.org"
schemaLocation="Person.xsd"/>
<xsd:import namespace="http://www.product.org"
schemaLocation="Product.xsd"/>
<xsd:element name="Company">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Person" type="per:personType"
maxOccurs="unbounded"/>
<xsd:element name="Product" type="pro:productType"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>[/XML]

Das ganze benutze ich nun in der Company.xml
[XML]<Company xmlns="http://www.company.org"
xmlns:pro="http://www.product.org"
xmlns:per="http://www.person.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.company.org
Company.xsd">
<Person>
<per:Name>John Doe</per:Name>
<per:SSN>123-45-6789</per:SSN>
</Person>
<Product>
<pro:Type>Widget</pro:Type>
</Product>
</Company>[/XML]

Ich benutze zur Zeit XMLspy als Editor und der spuckt mir einen Fehler am Knoten "Person" aus.
Java:
File C:\Dokumente und Einstellungen\eyildiz\Desktop\Test\ns\Company.xml is not valid.
	Element <Person> is not allowed under element <Company>.
		Reason: The following elements are expected at this location (see below)
			<Person>
		Error location: Company / Person
		Details
			cvc-model-group: Element <Person> unexpected by type '{anonymous}' of element <Company>.
			cvc-elt.5.2.1: The element <Company> is not valid with respect to the actual type definition '{anonymous}'.

Habe leider nicht rausbekommen wo der Fehler liegt. Hoffe das mir eine/r weiterhelfen kann.

Grüße
sylo
 

Niki

Top Contributor
dein Attribut xsi:schemaLocation im xml ist falsch, liegt die Datei im selben Ordner funktionierts
Java:
<Company xmlns="http://www.company.org"
         xmlns:pro="http://www.product.org"
         xmlns:per="http://www.person.org"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="Company.xsd">        
         
        <Person>
                <per:Name>John Doe</per:Name>
                <per:SSN>123-45-6789</per:SSN>
        </Person>
        <Product>
                <pro:Type>Widget</pro:Type>
        </Product>
</Company>
 

Ähnliche Java Themen

Neue Themen


Oben