Solved

Help in creating a small inline schema for a xml file

Posted on 2006-06-30
6
431 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:ianinspain
  • 2
  • 2
  • 2
6 Comments
 
LVL 22

Accepted Solution

by:
_TAD_ earned 250 total points
Comment Utility

Here is a sample of an inline schema that I use within my XML.  It looks a little clunky, but it is rather generic so it can work with many different applications.  I can help depose this if it is too confusing.

<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
      <s:Schema id="RowsetSchema">
            <s:ElementType name="row" content="eltOnly" rs:updatable="true">
                  <s:AttributeType name="PARAM" rs:number="1" rs:write="true">
                        <s:datatype dt:type="string" dt:maxLength="255" rs:precision="0" rs:maybenull="false"/>
                  </s:AttributeType>
                  <s:AttributeType name="DATATYPE" rs:number="2" rs:write="true">
                        <s:datatype dt:type="string" dt:maxLength="20" rs:precision="0" rs:maybenull="false"/>
                  </s:AttributeType>
                  <s:AttributeType name="DIRECTION" rs:number="3" rs:write="true">
                        <s:datatype dt:type="string" dt:maxLength="20" rs:precision="0" rs:maybenull="false"/>
                  </s:AttributeType>
                  <s:AttributeType name="VALUE_TEXT" rs:number="4" rs:nullable="true" rs:write="true">
                        <s:datatype dt:type="string" dt:maxLength="1024" rs:precision="0" rs:long="true" rs:maybenull="false"/>
                  </s:AttributeType>
                  <s:AttributeType name="VALUE_NUMERIC" rs:number="5" rs:nullable="true" rs:write="true">
                        <s:datatype dt:type="float" dt:maxLength="8" rs:precision="0" rs:fixedlength="true" rs:maybenull="false"/>
                  </s:AttributeType>
                  <s:AttributeType name="VALUE_DATETIME" rs:number="6" rs:nullable="true" rs:write="true">
                        <s:datatype dt:type="dateTime" rs:dbtype="timestamp" dt:maxLength="16" rs:scale="0" rs:precision="0" rs:fixedlength="true" rs:maybenull="false"/>
                  </s:AttributeType>
                  <s:AttributeType name="VALUE_FILE_NAME" rs:number="7" rs:nullable="true" rs:write="true">
                        <s:datatype dt:type="string" dt:maxLength="255" rs:precision="0" rs:maybenull="false"/>
                  </s:AttributeType>
                  <s:AttributeType name="VALUE_FILE_SIZE" rs:number="8" rs:nullable="true" rs:write="true">
                        <s:datatype dt:type="float" dt:maxLength="8" rs:precision="0" rs:fixedlength="true" rs:maybenull="false"/>
                  </s:AttributeType>
                  <s:AttributeType name="VALUE_FILE_CONTENTTYPE" rs:number="9" rs:nullable="true" rs:write="true">
                        <s:datatype dt:type="string" dt:maxLength="255" rs:precision="0" rs:maybenull="false"/>
                  </s:AttributeType>
                  <s:AttributeType name="VALUE_FILE_DESCRIPTION" rs:number="10" rs:nullable="true" rs:write="true">
                        <s:datatype dt:type="string" dt:maxLength="255" rs:precision="0" rs:maybenull="false"/>
                  </s:AttributeType>
                  <s:AttributeType name="VALUE_FILE_ORIGINALPATH" rs:number="11" rs:nullable="true" rs:write="true">
                        <s:datatype dt:type="string" dt:maxLength="255" rs:precision="0" rs:maybenull="false"/>
                  </s:AttributeType>
                  <s:AttributeType name="VALUE_FILE_DATELASTMODIFIED" rs:number="12" rs:nullable="true" rs:write="true">
                        <s:datatype dt:type="dateTime" rs:dbtype="timestamp" dt:maxLength="16" rs:scale="0" rs:precision="0" rs:fixedlength="true" rs:maybenull="false"/>
                  </s:AttributeType>
                  <s:AttributeType name="VALUE_FILE_PATH" rs:number="13" rs:nullable="true" rs:write="true">
                        <s:datatype dt:type="string" dt:maxLength="255" rs:precision="0" rs:maybenull="false"/>
                  </s:AttributeType>
                  <s:extends type="rs:rowbase"/>
            </s:ElementType>
      </s:Schema>
      <rs:data>
            <rs:insert>
                  <z:row PARAM="DATA" DATATYPE="FILE" DIRECTION="IN" VALUE_FILE_NAME="dataOUT.fdf" VALUE_FILE_SIZE="642" VALUE_FILE_CONTENTTYPE="application/vnd.fdf" VALUE_FILE_ORIGINALPATH="C:\Inetpub\jsiworkflow\wwwroot\wfgen\app\eformpdf\files\2006\06\14\6027\1\dataOUT.fdf" VALUE_FILE_DATELASTMODIFIED="2006-06-14T13:16:21" VALUE_FILE_PATH="C:\Inetpub\jsiworkflow\wwwroot\wfgen\pro\files\dataset\runtime\2006\06\14\334684-1.fdf" rs:forcenull="VALUE_FILE_DESCRIPTION"/>
                  <z:row PARAM="PROXY_TO_SERVICE" DATATYPE="FILE" DIRECTION="INOUT" VALUE_FILE_NAME="seed.txt" VALUE_FILE_SIZE="2" VALUE_FILE_CONTENTTYPE="text/plain" VALUE_FILE_ORIGINALPATH="C:\Documents and Settings\tdegen\Desktop\seed.txt" VALUE_FILE_PATH="C:\Inetpub\jsiworkflow\wwwroot\wfgen\pro\files\dataset\runtime\2006\06\14\334685-1.txt" rs:forcenull="VALUE_FILE_DESCRIPTION VALUE_FILE_DATELASTMODIFIED"/>
                  <z:row PARAM="TEMPLATE" DATATYPE="FILE" DIRECTION="IN" VALUE_FILE_NAME="299030-1.pdf" VALUE_FILE_SIZE="7337" VALUE_FILE_CONTENTTYPE="application/pdf" VALUE_FILE_ORIGINALPATH="C:\Documents and Settings\tdegen\Desktop\Document1.pdf" VALUE_FILE_DATELASTMODIFIED="2006-06-14T13:16:21" VALUE_FILE_PATH="C:\Inetpub\jsiworkflow\wwwroot\wfgen\pro\files\dataset\runtime\2006\06\14\334686-1.pdf" rs:forcenull="VALUE_FILE_DESCRIPTION"/>
                  <z:row PARAM="WFGEN_TO_PROXY" DATATYPE="FILE" DIRECTION="INOUT" VALUE_FILE_NAME="seed.txt" VALUE_FILE_SIZE="2" VALUE_FILE_CONTENTTYPE="text/plain" VALUE_FILE_ORIGINALPATH="C:\Documents and Settings\tdegen\Desktop\seed.txt" VALUE_FILE_PATH="C:\Inetpub\jsiworkflow\wwwroot\wfgen\pro\files\dataset\runtime\2006\06\14\334687-1.txt" rs:forcenull="VALUE_FILE_DESCRIPTION VALUE_FILE_DATELASTMODIFIED"/>
            </rs:insert>
      </rs:data>
</xml>
0
 
LVL 22

Expert Comment

by:_TAD_
Comment Utility


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>
0
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 250 total points
Comment Utility
Hi ianinspain,

I have a feeling your question is more...
can you help me with my schema

here is a schema that validates the above XML and makes sure the TITLES has an integer

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

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

you can wrap it in an envelope as TAD suggests

Cheers!
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:ianinspain
Comment Utility
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>
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
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
0
 

Author Comment

by:ianinspain
Comment Utility
thanks all

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now