Over a million developers have joined DZone.

Introduction to the XCO

DZone's Guide to

Introduction to the XCO

Don't just sit there — read David Gao's short intro to the XCO, code blocks included!

· Web Dev Zone ·
Free Resource

Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.

1. Introduction to the XCO

XCO (XSON common object) is a common data object, the underlying use of a Map-like data structure for data storage access, to facilitate the way of XML data object serialization and deserialization, suitable for isomorphism, Data transfer, and exchange between heterogeneous systems.

2. Supported Data Types

  • A. 8 basic types (byte, boolean, short, int, long, float, double, char)
  • B. 8 basic types of arrays
  • E. String, String array, String collection
  • C. Date, sql.Date, sql.Time
  • D. BigInteger, BigDecimal
  • E. XCO, XCO array, XCO set

3. XML Format

<?xml version="1.0" encoding="UTF-8"?>
    <B K="byteVal" V="3"/>
    <O K="booleanVal" V="true"/>
    <H K="shortVal" V="5"/>
    <I K="intVal" V="2"/>
    <L K="longVal" V="2"/>
    <F K="floatVal" V="2.0"/>
    <D K="doubleVal" V="-0.3"/>
    <C K="charVal" V="x"/>
    <S K="stringVal" V="hello world"/>
    <A K="dateTimeVal" V="2016-09-02 16:58:25"/>
    <E K="dateVal" V="2016-09-02"/>
    <G K="TimeVal" V="16:58:25"/>
    <K K="bigIntegerVal" V="1380000"/>
    <M K="bigDecimal" V="1380000.9999"/>
    <X K="xcoVal"/>
    <IA K="intArray" V="1,3,5,8"/>
    <SA K="stringArray">
        <S V="aa"/>
        <S V="bb"/>
        <S V="cc"/>
    <SL K="stringList"/>
    <SS K="stringSet"/>


a. Take this as an example:<H K="shortVal" V="5"/>
    H: data type identification, the current marked short type
    K: key
    V: specific values
b. Description of the data type identification
    B: byte
    H: short
    I: int
    L: Long
    F: float
    D: double
    C: char
    O: boolean
    S: String
    X: xco
    A: date
    E: sql.date
    G: sql.time
    J: sql.timestamp
    K: bigInteger
    M: bigDecimal
    See org.xson.common.object.DataType for more details

4. Common Methods

a. Assignment

    // Set a value of type int, field to key
    public final void setIntegerValue(String field, int var)

    // Set a value of type String, field for the key
    public final void setStringValue(String field, String var)


b. Taking Value

    // Gets a value of type int, field is key
    public final int getIntegerValue(String field)

    // Gets a value of type String, field is key
    public final String getStringValue(String field)


c. Serialization

    // The XCO object to XML way serialization
    public String toXMLString() 

    // Deserializes an XML string from an XML string into an XCO object
    public static XCO fromXML(String xml)

    // The XCO object to JSON way serialization
    public String toJSON()

5. Examples of Use

    XCO xco = new XCO();

    // Set the base type
    xco.setByteValue("byteVal", (byte) 3);
    xco.setBooleanValue("booleanVal", true);
    xco.setShortValue("shortVal", (short) 5);
    xco.setIntegerValue("intVal", 2);
    xco.setLongValue("longVal", 2L);
    xco.setFloatValue("floatVal", 2.0F);
    xco.setDoubleValue("doubleVal", -0.3D);
    xco.setCharValue("charVal", 'x');

    // Set the object type
    xco.setStringValue("stringVal", "hello world");
    xco.setDateTimeValue("dateTimeVal", new java.util.Date());
    xco.setDateValue("dateVal", new java.sql.Date(System.currentTimeMillis()));
    xco.setTimeValue("TimeVal", new java.sql.Time(System.currentTimeMillis()));
    xco.setBigIntegerValue("bigIntegerVal", new BigInteger("1380000"));
    xco.setBigDecimalValue("bigDecimal", new BigDecimal("1380000.9999"));
    xco.setXCOValue("xcoVal", new XCO());

    // Set the array
    xco.setIntegerArrayValue("intArray", new int[] { 1, 3, 5, 8 });
    xco.setStringArrayValue("stringArray", new String[] { "aa", "bb", "cc" });

    // Set the collection
    List<String> list = new ArrayList<String>();
    xco.setStringListValue("stringList", list);
    Set<String> set = new TreeSet<String>();
    xco.setStringSetValue("stringSet", set);

    // XML serialization
    String xml = xco.toXMLString();
    // deserialize
    XCO newXco = XCO.fromXML(xml);

    // taking value
    byte byteVal = xco.getByteValue("byteVal");
    boolean booleanVal = xco.getBooleanValue("booleanVal");
    short shortVal = xco.getShortValue("shortVal");
    int intVal = xco.getIntegerValue("intVal");
    long longVal = xco.getLongValue("longVal");
    float floatVal = xco.getFloatValue("floatVal");
    double doubleVal = xco.getDoubleValue("doubleVal");
    String stringVal = xco.getStringValue("stringVal");
    XCO xcoVal = xco.getXCOValue("xcoVal"); 

6. Design Drawings

Design drawings

What’s the best way to boost the efficiency of your product team and ship with confidence? Check out this ebook to learn how Sentry's real-time error monitoring helps developers stay in their workflow to fix bugs before the user even knows there’s a problem.

xml ,common data object ,xco ,web dev

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}