Solved

Help in creating a small inline schema for a xml file

Posted on 2006-06-30
6
445 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 22

Accepted Solution

by:
_TAD_ earned 250 total points
ID: 17018921

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_
ID: 17018997


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
ID: 17027368
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ianinspain
ID: 17030040
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
ID: 17030128
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
ID: 17147081
thanks all

0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will learn how to count occurrences of each item in an array.
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…

710 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