Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help in creating a small inline schema for a xml file

Posted on 2006-06-30
6
Medium Priority
?
453 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 1000 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 1000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

926 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