There are some Google API introductions, but in actual development we may need to convert the JSON data returned by the Google RESTful API into XML data input into a third-party system, which is very common in enterprise application integration. Then there is the question of how to ensure that the converted XML data format is canonical, which requires XML Schema (XML) for validation. Now the point is, we only know the JSON schema of the Google API, but Google restful does not provide the XML schema that returns the data, so what will the XML schema look like? Let me take the Google Tasks API as an example. From the URL below we can see information about the Google Tasks RESTful API JSON schema: Https://www.googleapis.com/discovery/v1/apis/tasks/v1/rest
So how do you translate the JSON schema for Google tasks into an XSD schema for XML? What will the XML schema look like? Please refer to the conversion implementation below.
<?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" t Ype= "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 "/&G T <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=" x S:string "minoccurs=" 0 "/> <xs:element name=" updated "form=" unqualified "type=" xs:string "minoccurs=" 0 "/&G T </xs:sequence> </xs:complexType> <xs:complextype name= "tasklists" > <xs:sequence> <xs:element name= "ETag" form= "unqualified" type= "xs:string" minoccurs= "0"/> <xs:element name= "I TEMs "form=" unqualified "type=" TaskList "minoccurs=" 0 "maxoccurs=" unbounded "/> <xs:element name=" kind "fo Rm= "Unqualified" type= "xs:string" minoccurs= "0"/> <xs:element name= "Nextpagetoken" form= "unqualified" Typ E= "xs:string" minoccurs= "0"/> </xs:sequence> </xs:complexType> <xs:complextype name= "Taskit EMS "> <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 nam E= "type" form= "unqualified" type= "xs:string" minoccurs= "0"/> </xs:sequence> </xs:complexType> <xs:complextype name= "Tasklinks" > <xs:sequence> <xs:element name= "items" form= "Unqualifie D "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" MAXOCCU rs= "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>