Simple question on XML Schema

N

Nimmi Srivastav

Greetings,

I have two newbie questions.

1) Using XML Schema, how can I describe an XML document in which the
root element is either A or B? Also, using DTD, how can the same be
achieved?

2) In an XML driven messaging system, is it a good design practice to
use XML documents with different root elements to indicate the message
version information? For example, the root element can be Ver1 or
Ver2. If the recipient receives XML content with root element Ver1,
it processes it as a version 1 message and if the recipient receives
XML content with root element Ver2, it processes it as a version 2
message. The structure of Ver1 message can be substantially different
from the structure of the Ver2 message.

Thanks,
Nimmi
 
M

Martin Honnen

Nimmi said:
1) Using XML Schema, how can I describe an XML document in which the
root element is either A or B? Also, using DTD, how can the same be
achieved?

I don't think DTD can do that.
As for a schema, any top level element you define in your schema can
serve as a root element so when you do e.g.

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="A">
<xs:complexType>
...
</xs:complexType>
</xs:element>

<xs:element name="B">
<xs:complexType>
...
</xs:complexType>
</xs:element>

</xs:schema>

then you allow 'A' or 'B' as a root element.
 
P

Peter Flynn

Martin said:
I don't think DTD can do that.

In a DTD, it's the same concent as in a Schema, in that any top-level
element type (one that is not in the content model of any other element
type) could be assumed to be a root element type, although the SGML
standard doesn't specify whether you have to make that assumption or
not, because in a DTD, *any* element type can be a root element type, eg

<!DOCTYPE td SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<td></td>

///Peter
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top