`

[转]SModel- 提供 XML , JSON , POJO 等结构化数据统一编程模型

阅读更多
SModel provides users a uniform way to access and manipulate structured model in the format of XML, JSON, POJO or other user defined data format from data source such as stream, database or others.

Base on SModel, Document Oriented Service(DOS) framework can employee a uniform set of APIs to read and manipulate different format of document.

Features
1) provides a uniform way to access and manipulate structure model, including: add, remove, query, move, update, and introspect data. SModel also provides mechanism to subscribe for the change event of the model manipulation.
2)supports to load model from XML, JSON, POJO, or user defined format.
3)supports to flush model to XML, JSON, POJO or user defined format.
4)supports to validate model according to SModel defined or user defined rule.
5)provides mechanism to extend the function of the model.
6)provides mechanism to subscribe for error or warning message of the SModel.

Two Minutes Reference
1)create a xml document
sample xml:
        <?xml version="1.0" encoding="UTF-8"?>
        <order id="order id 1" name="order name 1">
            <orderDate>2009-09-06 20:36:01.196</orderDate>
            <items>
                <item count="100" id="item id 1" name="item name 1" price="10.3" />
            </items>
        </order>


IXmlModel orderModel = new XmlModel("order");
      orderModel.setProperty("id", "order id 1");
      orderModel.setProperty("name", "order name 1");
      orderModel.setChildText("orderDate", Utils.buildTimestamp(new Timestamp(new Date().getTime())));
                
      IXmlModel items = (IXmlModel) orderModel.addChild("items");
      IXmlModel item = (IXmlModel) items.addChild("item");
      item.setProperty("id", "item id 1");
      item.setProperty("name", "item name 1");
      item.setProperty("price", 10.3);
      item.setProperty("count", 100);
                
      XmlModelService.flushToXml(orderModel, "d:/order.xml");

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics