embedding schema in the xml document..

Discussion in 'XML' started by marcus, Mar 2, 2004.

  1. marcus

    marcus Guest

    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
    marcus, Mar 2, 2004
    #1
    1. Advertising

  2. marcus wrote:

    > 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.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Mar 2, 2004
    #2
    1. Advertising

  3. marcus

    marcus Guest

    Martin Honnen wrote:

    > 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
    marcus, Mar 2, 2004
    #3
  4. marcus <> wrote in message >
    > 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.
    Toivo Lainevool, Mar 3, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page