eine Schema für ein andere Schema XML

DungNghe

Mitglied
Hallo Leute,
Ich bin neu hier und möchte eine Frage stellen, ob jemandem mir helfen kann.
Meine Fall ist so, ich habe eine List von mehre XML Schemas in eine XML Datein, und möchte für diese XML ein Schema definieren. wie geht das?
Hier ist mein XML Datein
Java:
<cep:TestRequest
	xmlns="http://www.congdong.de"
	xmlns:cep="http://www.congdong.de"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="www.congdong.de file://EventTypeRepository.xsd"
	>
	
	<eventTest>
		<eventTypeId>TestAdME</eventTypeId>
		<pattern></pattern>
		<xsd:schema>
			<xsd:element name="TestADME">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="Ready" type="xsd:boolean"></xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
		</xsd:schema>
	</eventTest>
	<eventTest>
		<eventTypeId>TestCMPD</eventTypeId>
		<pattern></pattern>
	       <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
			<xsd:element name="TestCMPD">
				<xsd:complexType>
					<xsd:sequence>
					<xsd:element name="CMPD" type="xsd:string"></xsd:element>
		    			<xsd:element name="Partner" type="xsd:string"></xsd:element>
		    			<xsd:element name="Result" type="xsd:string"></xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
		</xsd:schema>

	</eventTest>
	<eventTest>
		<eventTypeId>TestAdME</eventTypeId>
		<pattern></pattern>
		<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
			<xsd:element name="ADME">
				<xsd:complexType>
				    <xsd:sequence>
					<xsd:element name="DrugReady" type="xsd:string"></xsd:element>
				    </xsd:sequence>
				</xsd:complexType>
			</xsd:element>
		</xsd:schema>
	</eventTest>

Und hier ist mein erst Versucht mit Schema:
Java:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	targetNamespace="www.congdong.de"
	xmlns="www.congdong.de"
	xmlns:cep="www.congdong.de"
	xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
	jaxb:version="2.0"
	elementFormDefault="qualified" attributeFormDefault="qualified">

	<xsd:complexType name="EventTest" >
		<xsd:sequence>
			<xsd:element name="eventTypeId" type="cep:EventTypeId">
			</xsd:element>
			<xsd:element name="pattern" type="xsd:string"></xsd:element>
			<xsd:element name="schema" type="xsd:anyType" >
	                    <xsd:annotation>
	                    	<xsd:appinfo><jaxb:dom/></xsd:appinfo>
	                    </xsd:annotation>
			</xsd:element>
		</xsd:sequence>
	</xsd:complexType>

Hast jemand Idee mir zu helfen, Node "xsd" in XML Datein zu definieren.
Danke schön
 
Du hast TestRequest nicht definiert, ausserdem kein Element für eventTest. Warum anyType statt xsd:schema? Warum überhaupt ein ganzes Schema in einem eventTest und nicht eine TypeDefinition oder Element Declaration?
 
@Wildcard: danke für schnell Antwort:
Du hast TestRequest nicht definiert, ausserdem kein Element für eventTest
-> sorry, ich hab vergessen wenn koppieren (copy/paste 🙂. Hier ist mein richtig schema:
Java:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="www.congdong.de"
    xmlns="www.congdong.de"
    xmlns:cep="www.congdong.de"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    jaxb:version="2.0"
    elementFormDefault="unqualified" attributeFormDefault="unqualified">

     <xsd:element name="TestRequest">
		<xsd:complexType>
			<xsd:sequence maxOccurs="unbounded" minOccurs="1">
				<xsd:element name="eventTest" type="cep:EventTest"></xsd:element>
			</xsd:sequence>
		</xsd:complexType>
		<xsd:key name="eventTypeIdMustBeUnique">
			<xsd:selector xpath="cep:eventTest" />
			<xsd:field xpath="cep:eventTypeId" />
		</xsd:key>
	</xsd:element>
    <xsd:complexType name="EventTest" >
        <xsd:sequence>
            <xsd:element name="eventTypeId" type="cep:EventTypeId">
            </xsd:element>
            <xsd:element name="pattern" type="xsd:string"></xsd:element>
            <xsd:element name="schema" type="xsd:anyType" >
                        <xsd:annotation>
                            <xsd:appinfo><jaxb:dom/></xsd:appinfo>
                        </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

Warum anyType statt xsd:schema?
-> Ich verbinde hier eine jaxb dom zu interpretieren ganz "xsd:schema" Node in XML file deswegen benutze ich type:anyType. (gibt es aber auch kein type:schema für eine element zu definieren oder? )

Warum überhaupt ein ganzes Schema in einem eventTest und nicht eine TypeDefinition oder Element Declaration?
-> Ich programiere mit Event processing, ich muss eine List von Event mit ein XML darstellen, in jede
Event wird ein EventTypeId, pattern und ein schema dargestellt. Und für die selbst Event List XML Datei brauche ich auch ein schema zu definieren. das ist mein Problem. Hast du Idee für eine Schema zu definieren ein andere Schema?
 
Zuletzt bearbeitet:
Ich habe etwas Schwierigkeiten dein Deutsch zu verstehen. Fällt es dir in Englisch vielleicht leichter?
-> Ich verbinde hier eine jaxb dom zu interpretieren ganz "xsd:schema" Node in XML file deswegen benutze ich type:anyType. (gibt es aber auch kein type:schema für eine element zu definieren oder? )
Du kannst den Type xsd:schema direkt verwenden. Dann ist klar das dort ein Schema hin muss und nicht 'irgendetwas'
 
I use a jaxb-Dom File to define the Content for the element "schema" so i use "type:anyType. I have tried to used "type:schema" like you say but there is an error (from eclipse):
Java:
src-resolve.4.2: Error resolving component 'xsd:schema'. It was detected that 'xsd:schema' is in namespace 
 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from 
 schema document 'file:///D:/Work/workspacenew/.../EventType.xsd'. If this is the incorrect namespace, perhaps the prefix of 'xsd:schema' 
 needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 
 'file:///D:/Work/workspacenew/.../
 EventType.xsd'.
 
First you need to import the XSD Namespace in order to reference Elements from the Schema for Schemas.
Second, xsd:schema is not a Type, but an Element Declaration and hence you need an Element Reference:
[XML]<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns="www.congdong.de" xmlns:cep="www.congdong.de" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="unqualified" jaxb:version="2.0" targetNamespace="www.congdong.de">
<xsd:import namespace="http://www.w3.org/2001/XMLSchema"/>
<xsd:element name="TestRequest">
<xsd:complexType>
<xsd:sequence maxOccurs="unbounded" minOccurs="1">
<xsd:element name="eventTest" type="cep:EventTest"/>
</xsd:sequence>
</xsd:complexType>
<xsd:key name="eventTypeIdMustBeUnique">
<xsd:selector xpath="cep:eventTest"/>
<xsd:field xpath="cep:eventTypeId"/>
</xsd:key>
</xsd:element>
<xsd:complexType name="EventTest">
<xsd:sequence>
<xsd:element name="eventTypeId" type="cep:EventTypeId">
</xsd:element>
<xsd:element name="pattern" type="xsd:string"/>
<xsd:element ref="xsd:schema">
<xsd:annotation>
<xsd:appinfo>
<jaxb:dom/>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

</xsd:schema>[/XML]
 
@Wildcard: thanks for your answer, i have tried to use element references like you advice but can not resolve. i have import namespace "namespace="http://www.w3.org/2001/XMLSchema"" but eclipse don´t know ref="xsd:schema.
Java:
src-resolve: Cannot resolve the name 'xsd:schema' to a(n) 'element declaration' component.
I think may be there is a namespace conflict (both schema in XML file and Schema file use xsd prefix).
I have tried to change the namespace from XML file like that
for the EventTypeList.xml File
Java:
<cep:TestRequest
    xmlns="http://www.congdong.de"
    xmlns:cep="http://www.congdong.de"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="www.congdong.de file://EventTypeRepository.xsd"
    >
    
    <eventTest>
        <eventTypeId>TestAdME</eventTypeId>
        <pattern></pattern>
        <xs:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema>
            <xs:element name="TestADME">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="Ready" type="xs:boolean"></xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
    </eventTest>
    <eventTest>
        <eventTypeId>TestCMPD</eventTypeId>
        <pattern></pattern>
           <xs:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xs:element name="TestCMPD">
                <xs:complexType>
                    <xs:sequence>
                    <xs:element name="CMPD" type="xs:string"></xs:element>
                        <xs:element name="Partner" type="xs:string"></xs:element>
                        <xs:element name="Result" type="xs:string"></xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
 
    </eventTest>
    <eventTest>
        <eventTypeId>TestAdME</eventTypeId>
        <pattern></pattern>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xs:element name="ADME">
                <xs:complexType>
                    <xs:sequence>
                    <xs:element name="DrugReady" type="xs:string"></xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
    </eventTest>
and the Schema is:
Java:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns="www.congdong.de" xmlns:cep="www.congdong.de" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="unqualified" jaxb:version="2.0" targetNamespace="www.congdong.de">
<xsd:import namespace="http://www.w3.org/2001/XMLSchema"/>  
     <xsd:element name="TestRequest">
        <xsd:complexType>
            <xsd:sequence maxOccurs="unbounded" minOccurs="1">
                <xsd:element name="eventTest" type="cep:EventTest"/>
            </xsd:sequence>
        </xsd:complexType>
        <xsd:key name="eventTypeIdMustBeUnique">
            <xsd:selector xpath="cep:eventTest"/>
            <xsd:field xpath="cep:eventTypeId"/>
        </xsd:key>
    </xsd:element>
    <xsd:complexType name="EventTest">
        <xsd:sequence>
            <xsd:element name="eventTypeId" type="cep:EventTypeId">
            </xsd:element>
            <xsd:element name="pattern" type="xsd:string"/>
            <xsd:element ref="xs:schema">
                        <xsd:annotation>
                            <xsd:appinfo>
            <jaxb:dom/>
          </xsd:appinfo>
                        </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    
 </xsd:schema>

but that come to an Error with "xs:schema" element
Java:
cvc-complex-type.2.4.d: Invalid content was found starting with element 'xs:schema'. No child element is 
 expected at this point.
and alse the same Error with ref="xs:schema". Can you give me some advice?
 
Zuletzt bearbeitet:
You defined the prefix to be xsd, but then you wrote xs:schema.
Correct would be
Code:
xsd:schema
 
that comes also Error
Java:
src-resolve: Cannot resolve the name 'xsd:schema' to a(n) 'element declaration' component.
.
i´m confused now...🙁
 
I think may be there is a namespace conflict (both schema in XML file and Schema file use xsd prefix).
Why should that matter? As long as each document is consistent in its namespace prefix declarations and usage everything is fine.
The XSD I posted above is valid. You can verify that by uploading it to an online Schema validator.
Eclipse WTP also recognizes it as a valid schema. I do not know which tool you are using that produces the above error message, but the example I posted is a correct schema definition.
 
@Wildcard: sorry for disturbing you but i can not jet import namespace "http://www.w3.org/2001/XMLSchema". that comes errors:

Java:
schema_reference.4: Failed to read schema document 'null', because 1) could not find the document; 2) the document could not be read; 3) the root element of the 
 document is not <xsd:schema>.

That may be because i have already import another namespace (i muss import another namespace to define element "EventTypeID" before, see schema unter). Can this be reason for the problem. Can we import multi namespace to a schema? (I have search many sites but there are no clear answer) and muss we also set a schemaLocation for the namespace "http://www.w3.org/2001/XMLSchema" ?
Thanks for your help


Java:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns="www.congdong.de" xmlns:cep="www.congdong.de" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="unqualified" jaxb:version="2.0" targetNamespace="www.congdong.de">

<xsd:import namespace="http://www.w3.org/2001/XMLSchema"/>  
<xsd:import namespace="http://congdong.de/wsn/t-1"> schemaLocation="t-1.xsd" </xsd:import>

     <xsd:element name="TestRequest">
        <xsd:complexType>
            <xsd:sequence maxOccurs="unbounded" minOccurs="1">
                <xsd:element name="eventTest" type="cep:EventTest"/>
            </xsd:sequence>
        </xsd:complexType>
        <xsd:key name="eventTypeIdMustBeUnique">
            <xsd:selector xpath="cep:eventTest"/>
            <xsd:field xpath="cep:eventTypeId"/>
        </xsd:key>
    </xsd:element>
    <xsd:complexType name="EventTest">
        <xsd:sequence>
            <xsd:element name="eventTypeId" type="cep:EventTypeId">
            </xsd:element>
            <xsd:element name="pattern" type="xsd:string"/>
            <xsd:element ref="xsd:schema">
                        <xsd:annotation>
                            <xsd:appinfo>
            <jaxb:dom/>
          </xsd:appinfo>
                        </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    
 </xsd:schema>
 
Zuletzt bearbeitet:
That may be because i have already import another namespace (i muss import another namespace to define element "EventTypeID" before, see schema unter). Can this be reason for the problem. Can we import multi namespace to a schema? (I have search many sites but there are no clear answer) and muss we also set a schemaLocation for the namespace "http://www.w3.org/2001/XMLSchema" ?
Thanks for your help
You can import as many namespaces as you want, this is not a problem.
The xml schema namespace itself should work properly without a schema location since it is a well known namespace.
Again, I do not know which tool you are using that gives you these errors, but I would blame the tool here...
 
just for someone who cares, i have resolved this problem by using a "any element", my schema for xsd Node is:
Java:
....
<xsd:any namespace="http://www.w3.org/2001/XMLSchema" processContents="lax">
	        	<xsd:annotation>
	            	<xsd:appinfo><jaxb:dom/></xsd:appinfo>
	        	</xsd:annotation>
</xsd:any>
...
Thanks @Wildcard for helping.
 

Zurück
Oben