前面说了一些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>

怎样用Google APIs和Google的应用系统进行集成(5)----怎样把Google Tasks的JSON Schema转换成XML的Schema(XSD)?的更多相关文章

  1. 怎样用Google APIs和Google的应用系统进行集成(8)----怎样把Google Blogger(博客)的JSON Schema转换成XML的Schema(XSD)?

    在Google RESTFul API中,Google Blogger API(Google博客API)应该和我们的生活离得近期:由于差点儿非常多人每天都在看博客,都在写博客,都听说过博客.在前面的G ...

  2. 怎样用Google APIs和Google的应用系统进行集成(4)----获得Access Token以通过一些Google APIs的OAuth2认证

    在上篇文章中: "怎样用Google APIs和Google的应用系统进行集成(3)----调用发现Google APIs的RESTful的服务"一文中,我们直接用jdk的java ...

  3. GPS模块输出的NMEA数据ddmm.mmmm转换成dd.ddddd并在google Earth Pro中描点

      GPS模块输出的数据是NMEA格式,其中GPGGA字段包含我们需要的经纬度信息. 例:$GPGGA,092204.999,4250.5589,S,14718.5084,E,1,04,24.4,12 ...

  4. 谷歌正式发布Google APIs Client Library for .NET

    好消息,特大好消息! 英文原文:Google API library for .NET paves the way for Google services on Windows phone 本月 17 ...

  5. Android SDK Manager Google Apis 下载

    本意是想利用google的gcm来实装android推送功能的,很遗憾, google貌似已经停止提供啥服务给国内了,或者说国内想继续使用google 服务暂时变得几乎不可能了.找了个代理来进行goo ...

  6. 怎样用Google APIs和Google的应用系统进行集成(3)----调用Google 发现(Discovery)API的RESTful服务

    说了这么多,那么首先同意我以Google Discovery RESTful服务为例,给大家演示怎样用最普通的Java代码调用Google Discovery RESTful服务. 引言: 在&quo ...

  7. 怎样用Google APIs和Google的应用系统进行集成(1)----Google APIs简介

    Google的应用系统提供了非常多的应用,比方 Google广告.Google 任务,Google 日历.Google blogger,Google Plus,Google 地图等等非常的多的应用,请 ...

  8. 如何使用Google APIs和Google应用系统集成(7)----在里面JSON兑换XML数据处理,JSON数据包括违规XML数据规范:XML节点名称不支持号码Java解

    笔者电话Google Calendar APIs的GetColors方法,其中(有关详细信息Google Calendar API已经Google API看到我的博文介绍的其余部分,目前,我们只取Go ...

  9. 怎样用Google APIs和Google的应用系统进行集成(2)----Google APIs的全部的RESTFul服务一览

    上篇文章,我提到了,Google APIs暴露了86种不同种类和版本号的API.我们能够通过在浏览器里面输入https://www.googleapis.com/discovery/v1/apis这个 ...

随机推荐

  1. python staticmethod,classmethod方法的使用和区别以及property装饰器的作用

    class Kls(object): def __init__(self, data): self.data = data def printd(self): print(self.data) @st ...

  2. Struts2实现登录流程

    本节将演示一个基本的登录流程,在登录界面中若输入正确的用户名和密码,跳转到登录成功界面:否则路转到登录失败界面. 1 建立一个名为LoginDemo的动态Web项目 2 添加struts2相关的jar ...

  3. Oracle数据迁移至HBase操作记录

    Oracle数据迁移至HBase操作记录 @(HBase) 近期需要把Oracle数据库中的十几张表T级别的数据迁移至HBase中,过程中遇到了许多苦难和疑惑,在此记录一下希望能帮到一些有同样需求的兄 ...

  4. poj 2778 AC自己主动机 + 矩阵高速幂

    // poj 2778 AC自己主动机 + 矩阵高速幂 // // 题目链接: // // http://poj.org/problem?id=2778 // // 解题思路: // // 建立AC自 ...

  5. 元素的数据存储-jQuery.data()与.data()

    jQuery提供的存储接口 jQuery.data( element, key, value ) //静态接口,存数据 jQuery.data( element, key ) //静态接口,取数据 . ...

  6. ASP.NET MVC & Web API Brief Introduction

    Pure Web Service(ASMX): Starting back in 2002 with the original release of .NET, a developer could f ...

  7. css颜色大全

    本文来自:http://www.cnblogs.com/axing/archive/2011/04/09/CSS.html CSS颜色代码大全: FFFFFF #DDDDDD #AAAAAA #888 ...

  8. silverlight客户端保存文件乱码问题

    最近做一个项目,有一个需求是这样的:服务端从数据库里获得数据,客户端保存为Excel文件 最初解决方案:服务端获得数据,通过ExcelPackage,Convert.ToBase64String将by ...

  9. 文本域textarea

      文本域 CreateTime--2017年5月23日15:12:08Author:Marydon 二.文本域 (一)语法 <textarea></textarea> (二) ...

  10. Struts2入门示例

    1.导入struts2需要的9个包到lib文件夹中 2.配置web.xml文件 <?xml version="1.0" encoding="UTF-8"? ...