如何用Google APIs和Google的應用系統進行整合(5)----如何把Google Tasks的JSON Schema轉換成XML的Schema(XSD)?

來源:互聯網
上載者:User

標籤:google apis   google tasks   xsd schema   

前面說了一些Google API的介紹,但是在實際的開發當中,我們可能需要把Google RESTful API返回的JSON資料轉換成XML資料輸入到第三方系統,這在公司專屬應用程式整合裡面非常的常見。那麼裡面就有一個問題,如何確保轉換後的XML資料格式是規範的,這就需要XML Schema(XML)來進行校正。現在關鍵是,我們只知道Google API的JSON的schema,但是Google RESTful並沒有提供返回資料的XML的schema,那麼XML的Schema將會是什麼樣子的呢?讓我以Google Tasks API為例子。從下面的URL我們可以看到Google Tasks RESTFul的API JSON Schema的資訊:https://www.googleapis.com/discovery/v1/apis/tasks/v1/rest

 

 

 

那麼,如何把Google Tasks的JSON Schema轉換成XML的XSD Schema?XML的Schema將會是什麼樣子的呢?請參考下面轉換實現。

<?xml version='1.0' encoding='UTF-8'?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">    <xs:complexType name="Task">        <xs:sequence>            <xs:element name="completed" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="deleted" form="unqualified" type="xs:boolean" minOccurs="0"/>            <xs:element name="due" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="etag" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="hidden" form="unqualified" type="xs:boolean" minOccurs="0"/>            <xs:element name="id" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="kind" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="links" form="unqualified" type="Tasklinks" minOccurs="0" maxOccurs="unbounded"/>            <xs:element name="notes" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="parent" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="position" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="selfLink" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="status" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="title" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="updated" form="unqualified" type="xs:string" minOccurs="0"/>        </xs:sequence>    </xs:complexType>    <xs:complexType name="TaskList">        <xs:sequence>            <xs:element name="etag" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="id" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="kind" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="selfLink" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="title" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="updated" form="unqualified" type="xs:string" minOccurs="0"/>        </xs:sequence>    </xs:complexType>    <xs:complexType name="TaskLists">        <xs:sequence>            <xs:element name="etag" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="items" form="unqualified" type="TaskList" minOccurs="0" maxOccurs="unbounded"/>            <xs:element name="kind" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="nextPageToken" form="unqualified" type="xs:string" minOccurs="0"/>        </xs:sequence>    </xs:complexType>    <xs:complexType name="Taskitems">        <xs:sequence>            <xs:element name="description" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="link" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="type" form="unqualified" type="xs:string" minOccurs="0"/>        </xs:sequence>    </xs:complexType>    <xs:complexType name="Tasklinks">        <xs:sequence>            <xs:element name="items" form="unqualified" type="Taskitems" minOccurs="0" maxOccurs="unbounded"/>        </xs:sequence>    </xs:complexType>    <xs:complexType name="Tasks">        <xs:sequence>            <xs:element name="etag" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="items" form="unqualified" type="Task" minOccurs="0" maxOccurs="unbounded"/>            <xs:element name="kind" form="unqualified" type="xs:string" minOccurs="0"/>            <xs:element name="nextPageToken" form="unqualified" type="xs:string" minOccurs="0"/>        </xs:sequence>    </xs:complexType>    <xs:element name="Task" type="Task"/>    <xs:element name="TaskList" type="TaskList"/>    <xs:element name="TaskLists" type="TaskLists"/>    <xs:element name="Tasks" type="Tasks"/></xs:schema>


 

 

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.