Solved

Help in creating a small inline schema for a xml file

Posted on 2006-06-30
6
433 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
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to echo 6 80
WCAG (Web Content Accessibility Guidelines) levels 3 66
Create html table using xsl 8 28
XSLT XML 4 13
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

911 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