embedding schema in the xml document..

M

marcus

Hi All,

I'm new to xml world and i was looking for a way
to embed the xml schema info in the xml document
itself. i tried the following:

--- xml schema + document combined ---

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">

<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

<?xml version="1.0"?>

<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com">

<to>Registrar</to>
<from>Student</from>
<heading>Reminder</heading>
<body>Transcripts requested ASAP</body>
</note>

-----

is this a valid thing to do ? xerces parser will not
parse the above xml. if i put the schema in another file
and refer the xsi:schemaLocation to the xsd file, the
parsing goes fine.

any help is greatly appreciated..

//marc
 
M

Martin Honnen

marcus said:
I'm new to xml world and i was looking for a way
to embed the xml schema info in the xml document
itself. i tried the following:

--- xml schema + document combined ---

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">

<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

<?xml version="1.0"?>

<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com">

<to>Registrar</to>
<from>Student</from>
<heading>Reminder</heading>
<body>Transcripts requested ASAP</body>
</note>

-----

is this a valid thing to do ? xerces parser will not
parse the above xml. if i put the schema in another file
and refer the xsi:schemaLocation to the xsd file, the
parsing goes fine.

What you have is not even well-formed as only one XML declaration
followed by exactly one root element is allowed.
I don't think it makes much sense to embed an XML schema into an
instance document.
 
M

marcus

Martin said:
What you have is not even well-formed as only one XML declaration
followed by exactly one root element is allowed.
I don't think it makes much sense to embed an XML schema into an
instance document.

the scenario is: an emdedded device has its server hold
the device config as a dom document inmemory. clients
across network can request device to change its config
by providing xml dom subtree that needs to be changed.

the idea was to send the schema of the subtree (as the
device config is made of small schema docs each referring
to the subtree that could be changed) along with the
server response so the clinets donot have to maintian
a list of schema docs.

from your description it looks like clients across the
nework would have to maintain the schema locally as
the device does not the computing power to serve the
schema docs over network.

any thoughts/comments/suggestions ?

Thanks !
//marc
 
T

Toivo Lainevool

marcus said:
the scenario is: an emdedded device has its server hold
the device config as a dom document inmemory. clients
across network can request device to change its config
by providing xml dom subtree that needs to be changed.

One option would be to use a DTD instead of W3C XML Schema. DTD can be
embedded into the document.

Toivo Lainevool
http://www.XMLPatterns.com - Develop effective DTDs and XML Schema
documents for your XML using structural design patterns.
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top