Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help in creating a small inline schema for a xml file

Posted on 2006-06-30
6
Medium Priority
?
450 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
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.
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…

722 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