Link to home
Start Free TrialLog in
Avatar of ianinspain
ianinspain

asked on

Help in creating a small inline schema for a xml file

Hi there,

I wonder if anybody can help, i need to return with my XML (from my webservice) an inline schema to describe the datatype of each field.

currently this is an example of what is returned, as you can seen the field "TITLES" needs to be a Integer.. which i believe is possible if i specify an inline schema for my XML doc.

  <?xml version="1.0" encoding="utf-8" ?>
- <response>
  <Error code="0" description="OK" />
- <myData>
- <Record>
  <COD>abcdef</COD>
  <NAMED>Company A</NAMED>
  <TITLES>560</TITLES>
  </Record>
- <Record>
  <COD>dfggh</COD>
  <NAMED>Company B</NAMED>
  <TITLES>30000</TITLES>
  </Record>
  </myData>
  </response>

Error code doesn't need to be described, just COD,NAMED and TITLES...

COD and NAMED are strings, and TITLES is an integer..

I would much appreciate if anyone can offer some help, i am a little stuck...

Thanks in advance

Ian
ASKER CERTIFIED SOLUTION
Avatar of _TAD_
_TAD_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of _TAD_
_TAD_



ick.

Ugly formatting.   Copy and paste the text into note pad or something (and make sure text-wrap is off).



simplified version:


<XML  {xml namespaces declared - s, dt, rs, z} >
  <s:{tag} {attribute}>
      {Define the schema}
  </s:{tag}>
  <rs:{tag} {attribute}>
      <z:{tag} {attribute} />   <!-- XML Data goes here -->
  </rs:{tag} {attribute}>
</XML>
SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ianinspain

ASKER

Thanks gertone, interesting... and how would this fit in ... within my current XML?

i.e. just after the <response>? or at the end.... where abouts exactly for inline schema?

Thanks.... here in my current xml file example again..

<?xml version="1.0" encoding="utf-8" ?>
- <response>
  <Error code="0" description="OK" />
- <myData>
- <Record>
  <COD>abcdef</COD>
  <NAMED>Company A</NAMED>
  <TITLES>560</TITLES>
  </Record>
- <Record>
  <COD>dfggh</COD>
  <NAMED>Company B</NAMED>
  <TITLES>30000</TITLES>
  </Record>
  </myData>
  </response>
If you read about inline schemata, it would be like this
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:schema>

    <xs:element name="response">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Error"/>
                <xs:element ref="myData"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
   
    <xs:element name="Error">
        <xs:complexType>
            <xs:attribute name="code"/>
            <xs:attribute name="description"/>
        </xs:complexType>
    </xs:element>
   
    <xs:element name="myData">
        <xs:complexType>
            <xs:sequence maxOccurs="unbounded">
                <xs:element ref="Record"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
   
    <xs:element name="Record">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="COD"/>
                <xs:element name="NAMED"/>
                <xs:element name="TITLES" type="xs:integer"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    </xs:schema>
    <dataroot xmlns:xsi=
        "http://www.w3.org/2000/10/XMLSchema-instance">
        <response>
            <Error code="0" description="OK" />
             <myData>
                 <Record>
                    <COD>abcdef</COD>
                    <NAMED>Company A</NAMED>
                    <TITLES>560</TITLES>
                </Record>
                <Record>
                    <COD>dfggh</COD>
                    <NAMED>Company B</NAMED>
                    <TITLES>30000</TITLES>
                </Record>
            </myData>
        </response>
    </dataroot>
    </root>

I am not sure this is a W3C standardised way of inlining schema
(if that exists at all)
but .net and java have ways to handle this

cheers
thanks all