on XML Schema

T

Thorsten

Hey there,

I have a question concerning xml schemas and its contained elements.
Let's say I have a schema (object.xsd) that defines an abstract element
type (i.e. abstractObject). Dervied from this type are concrete types
(i.e. house, car...).
Now, I have an xml document that expects information about a datatype
in xml schema format. How can I now define that it is supposed to
expect an element of type "house"? Of course I can just refer to
"object.xsd". But that would mean that entries of type "car" would be
accepted as well. What possibilities do I have to restrict the schema
definition to the type "house"?

Thanks in advance,
Thorsten
 
M

Martin Honnen

Thorsten said:
Hey there,

I have a question concerning xml schemas and its contained elements.
Let's say I have a schema (object.xsd) that defines an abstract element
type (i.e. abstractObject). Dervied from this type are concrete types
(i.e. house, car...).
Now, I have an xml document that expects information about a datatype
in xml schema format. How can I now define that it is supposed to
expect an element of type "house"?

Well in the schema you would use
<xs:element name="someName" type="house"/>
to define an element of the house type. Then an XML instance document to
be validated against the schema needs to have an element of type house.
 
G

George Bina

Hi Thorsten,

It is not very clear for me what you want exactly. In addition to
Martin's answer: if you have an element of type abstractObject then in
the instance document you can use the xsi:type attribute to specify the
type to house for instance, where xsi maps to the schema instance
namespace: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Best Regards,
George
 
T

Thorsten

Thanks to both of you.

I think George's advice might help me. To clearify my problem: I work
with web services and one of them awaits a URL, where the data to
process is deposited. In addition it expects a reference to a schema
which describes the data structure of the data to process. Back to my
example: let's say I want the web service to process a data of type
"house" i have to post the URL to the house object and I have to
specify the schema for "house". All I can do is specify
"..../object.xsd" but to me that is too general, because the web
service would then accept all other objects defined in "objects.xsd",
but might not be able to process them.

Hope that's more understandable,
regards,
Thorsten
 
M

Martin Honnen

Thorsten said:
I think George's advice might help me. To clearify my problem: I work
with web services and one of them awaits a URL, where the data to
process is deposited. In addition it expects a reference to a schema
which describes the data structure of the data to process. Back to my
example: let's say I want the web service to process a data of type
"house" i have to post the URL to the house object and I have to
specify the schema for "house". All I can do is specify
"..../object.xsd" but to me that is too general, because the web
service would then accept all other objects defined in "objects.xsd",
but might not be able to process them.

A schema can define types but it can also define elements and usually
does. So you would define a schema that defines an element of that house
type.
 
T

Thorsten

Ok, that's what I'll do.
I thought that there is maybe another way than creating a new schema
for the subtype

Thanks a lot for you help guys!
Thorsten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top