| <!-- |
| /*************************************************************************************************************************** |
| * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations under the License. |
| ***************************************************************************************************************************/ |
| --> |
| |
| XML Methodology |
| |
| <p> |
| The following examples show how different data types are represented in XML. |
| They mirror how the data structures are represented in JSON. |
| </p> |
| |
| <h5 class='topic'>Simple types</h5> |
| <p> |
| The representation of loose (not a direct bean property value) simple types are shown below: |
| </p> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>XML</th> |
| </tr> |
| <tr> |
| <td>string</td> |
| <td class='code'><js>'foo'</js></td> |
| <td class='code'><xt><string></xt>foo<xt></string></xt></td> |
| </tr> |
| <tr> |
| <td>boolean</td> |
| <td class='code'><jk>true</jk></td> |
| <td class='code'><xt><boolean></xt>true<xt></boolean></xt></td> |
| </tr> |
| <tr> |
| <td>integer</td> |
| <td class='code'>123</td> |
| <td class='code'><xt><number></xt>123<xt></number></xt></td> |
| </tr> |
| <tr> |
| <td>float</td> |
| <td class='code'>1.23</td> |
| <td class='code'><xt><number></xt>1.23<xt></number></xt></td> |
| </tr> |
| <tr> |
| <td>null</td> |
| <td class='code'><jk>null</jk></td> |
| <td class='code'><xt><null/></xt></td> |
| </tr> |
| </table> |
| |
| <h5 class='topic'>Maps</h5> |
| <p> |
| Loose maps and beans use the element <xt><object></xt> for encapsulation. |
| </p> |
| <p> |
| <xa>_type</xa> attributes are added to bean properties or map entries if the type cannot be inferred |
| through reflection (e.g. an <c>Object</c> or superclass/interface value type). |
| </p> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>XML</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| Map<String,String> |
| </td> |
| <td class='code'> |
| { |
| k1: <js>'v1'</js> |
| k2: <jk>null</jk> |
| } |
| </td> |
| <td class='code'><xt> |
| <object> |
| <k1><xv>v1</xv></k1> |
| <k2 <xa>_type</xa>=<xs>'null'</xs>/> |
| </object> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| Map<String,Number> |
| </td> |
| <td class='code'> |
| { |
| k1: 123, |
| k2: 1.23, |
| k3: <jk>null</jk> |
| } |
| </td> |
| <td class='code'><xt> |
| <object> |
| <k1><xv>123</xv></k1> |
| <k2><xv>1.23</xv></k2> |
| <k3 <xa>_type</xa>=<xs>'null'</xs>/> |
| </object> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| Map<String,Object> |
| </td> |
| <td class='code'> |
| { |
| k1: <js>'v1'</js> |
| k2: 123, |
| k3: 1.23, |
| k4: <jk>true</jk>, |
| k5: <jk>null</jk> |
| } |
| </td> |
| <td class='code'><xt> |
| <object> |
| <k1><xv>v1</xv></k1> |
| <k2 <xa>_type</xa>=<xs>'number'</xs>><xv>123</xv></k2> |
| <k3 <xa>_type</xa>=<xs>'number'</xs>><xv>1.23</xv></k3> |
| <k4 <xa>_type</xa>=<xs>'boolean'</xs>><xv>true</xv></k4> |
| <k5 <xa>_type</xa>=<xs>'null'</xs>/> |
| </object> |
| </xt></td> |
| </tr> |
| </table> |
| |
| <h5 class='topic'>Arrays</h5> |
| <p> |
| Loose collections and arrays use the element <xt><array></xt> for encapsulation. |
| </p> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>XML</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| String[] |
| </td> |
| <td class='code'> |
| [ |
| <js>'foo'</js> |
| <jk>null</jk> |
| ] |
| </td> |
| <td class='code'><xt> |
| <array> |
| <string><xv>foo</xv></string> |
| <null/> |
| </array> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| Number[] |
| </td> |
| <td class='code'> |
| [ |
| 123, |
| 1.23, |
| <jk>null</jk> |
| ] |
| </td> |
| <td class='code'><xt> |
| <array> |
| <number><xv>123</xv></number> |
| <number><xv>1.23</xv></number> |
| <null/> |
| </array> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| Object[] |
| </td> |
| <td class='code'> |
| [ |
| <js>'foo'</js>, |
| 123, |
| 1.23, |
| <jk>true</jk>, |
| <jk>null</jk> |
| ] |
| </td> |
| <td class='code'><xt> |
| <array> |
| <string><xv>foo</xv></string> |
| <number><xv>123</xv></number> |
| <number><xv>1.23</xv></number> |
| <boolean><xv>true</xv></boolean> |
| <null/> |
| </array> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| String[][] |
| </td> |
| <td class='code'> |
| [ |
| [<js>'foo'</js>, <jk>null</jk>], |
| <jk>null</jk>, |
| ] |
| </td> |
| <td class='code'><xt> |
| <array> |
| <array> |
| <string><xv>foo</xv></string> |
| <null/> |
| </array> |
| <null/> |
| </array> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <jk>int</jk>[] |
| </td> |
| <td class='code'> |
| [ |
| 123 |
| ] |
| </td> |
| <td class='code'><xt> |
| <array> |
| <number><xv>123</xv></number> |
| </array> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <jk>boolean</jk>[] |
| </td> |
| <td class='code'> |
| [ |
| <jk>true</jk> |
| ] |
| </td> |
| <td class='code'><xt> |
| <array> |
| <boolean><xv>true</xv></boolean> |
| </array> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| List<String> |
| </td> |
| <td class='code'> |
| [ |
| <js>'foo'</js> |
| <jk>null</jk> |
| ] |
| </td> |
| <td class='code'><xt> |
| <array> |
| <string><xv>foo</xv></string> |
| <null/> |
| </array> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| List<Number> |
| </td> |
| <td class='code'> |
| [ |
| 123, |
| 1.23, |
| <jk>null</jk> |
| ] |
| </td> |
| <td class='code'><xt> |
| <array> |
| <number><xv>123</xv></number> |
| <number><xv>1.23</xv></number> |
| <null/> |
| </array> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| List<Object> |
| </td> |
| <td class='code'> |
| [ |
| <js>'foo'</js>, |
| 123, |
| 1.23, |
| <jk>true</jk>, |
| <jk>null</jk> |
| ] |
| </td> |
| <td class='code'><xt> |
| <array> |
| <string><xv>foo</xv></string> |
| <number><xv>123</xv></number> |
| <number><xv>1.23</xv></number> |
| <boolean><xv>true</xv></boolean> |
| <null/> |
| </array> |
| </xt></td> |
| </tr> |
| </table> |
| |
| <h5 class='topic'>Beans</h5> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>XML</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| <jk>class</jk> MyBean { |
| <jk>public</jk> String a; |
| <jk>public</jk> <jk>int</jk> b; |
| <jk>public</jk> Object c; <jc>// String value</jc> |
| <jk>public</jk> Object d; <jc>// Integer value</jc> |
| <jk>public</jk> MyBean2 e; |
| <jk>public</jk> String[] f; |
| <jk>public</jk> <jk>int</jk>[] g; |
| } |
| <jk>class</jk> MyBean2 { |
| String h; |
| } |
| </td> |
| <td class='code'> |
| { |
| <jok>a</jok>: <jov>'foo'</jov>, |
| <jok>b</jok>: <jov>123</jov>, |
| <jok>c</jok>: <jov>'bar'</jov>, |
| <jok>d</jok>: <jov>456</jov>, |
| <jok>e</jok>: { |
| <jok>h</jok>: <jov>'baz'</jov> |
| } |
| <jok>f</jok>: [<jov>'qux'</jov>] |
| <jok>g</jok>: [<jov>789</jov>] |
| } |
| </td> |
| <td class='code'><xt> |
| <object> |
| <a><xv>foo</xv></a> |
| <b><xv>123</xv></b> |
| <c><xv>bar</xv></c> |
| <d <xa>_type</xa>=<xs>'number'</xs>><xv>456</xv></d> |
| <e> |
| <h><xv>baz</xv></h> |
| </e> |
| <f> |
| <string><xv>qux</xv></string> |
| </f> |
| <g> |
| <number><xv>789</xv></number> |
| </g> |
| </object> |
| </xt></td> |
| </tr> |
| </table> |
| |
| <h5 class='topic'>Beans with Map properties</h5> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>XML</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| <jk>class</jk> MyBean { |
| <jk>public</jk> Map<String,String> a; |
| <jk>public</jk> Map<String,Number> b; |
| <jk>public</jk> Map<String,Object> c; |
| } |
| </td> |
| <td class='code'> |
| { |
| <jok>a</jok>: { |
| <jok>k1</jok>: <jov>'foo'</jov> |
| }, |
| <jok>b</jok>: { |
| <jok>k2</jok>: <jov>123</jov> |
| }, |
| <jok>c</jok>: { |
| <jok>k3</jok>: <jov>'bar'</jov>, |
| <jok>k4</jok>: <jov>456</jov>, |
| <jok>k5</jok>: <jov>true</jov>, |
| <jok>k6</jok>: <jov>null</jov> |
| } |
| } |
| </td> |
| <td class='code'><xt> |
| <object> |
| <a> |
| <k1><xv>foo</xv></k1> |
| </a> |
| <b> |
| <k2><xv>123</xv></k2> |
| </b> |
| <c> |
| <k3><xv>bar</xv></k3> |
| <k4 <xa>_type</xa>=<xs>'number'</xs>><xv>456</xv></k4> |
| <k5 <xa>_type</xa>=<xs>'boolean'</xs>><xv>true</xv></k5> |
| <k6 <xa>_type</xa>=<xs>'null'</xs>/> |
| </c> |
| </object> |
| </xt></td> |
| </tr> |
| </table> |