正 文

用 AXIOM 促进 XML 处理


www.7dspace.com  更新日期:2005-10-26 2:35:01  七度空间


      现在可以构造包装器元素 line-item 了:

OMElement lineItem= factory.createOMElement("line-item", poNs);

      接下来创建 line-item 元素相关的子元素和属性。

      最好用下面的方式创建元素属性:

lineItem.addAttribute("quantity", "2", poNs);

      与其他元素一样创建子元素,然后按照下面的方式结合到父元素中:

   OMElement description= factory.
      createOMElement("description", poNs);
         description.setText("Burnham's Celestial Handbook, Vol 2");
         lineItem.addChild(description);

      类似地,也添加 price 子元素:

   OMElement price= factory.createOMElement("price", poNs);
         price.setText("19.89");
         lineItem.addChild(price);

     清单 2 显示了完整的代码片段。

     清单 2.通过程序创建 line item

   OMFactory factory = OMAbstractFactory.getOMFactory();

         OMNamespace poNs =
         factory.createOMNamespace("http://openuri.org/easypo", "po");

         OMElement lineItem =
         factory.createOMElement("line-item", poNs);
         lineItem.addAttribute("quantity", "2", poNs);

         OMElement description =
         factory.createOMElement("description", poNs);
         description.setText("Burnham's Celestial Handbook, Vol 2");
         lineItem.addChild(description);

         OMElement price = factory.createOMElement("price", poNs);
         price.setText("19.89");
         lineItem.addChild(price);

7页,页码:[1] [2] [3] [4] [5] [6] [7] 

上一篇:用JAXB生成一个XML文档
下一篇:架设局域网升级服务器 用WSUS打补丁
作者:Eran Chinthaka  来源:developerWorks中国 ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐