Castor进行XML数据绑定时的一点问题

2007-08-01 15:56
Castor XML is an XML databinding framework. Unlike the two main XML APIs, DOM (Document Object Model) and SAX (Simple API for XML) which deal with the structure of an XML document, Castor enables one to deal with the data defined in an XML document through an object model which represents that data.
Castor能把Java对象和XML文档进行转换,使用户从复杂的XML解析中解放出来,更关注于数据而不是文档。
它支持从schema生成Java类,事实上我也这么做了,但是一个xsd可能生成多个存在引用关系的Java类,这不是我想要的。为简单计,我认为应该是一个Java类对应一个XML文档。
那另外一种办法是用mapping,自己定义对象的field到文档的element的转换。这里碰到一个小小的问题,
org.exolab.castor.mapping.MappingException: Could not find the class XXXX
网上搜到的解决办法如下: How to get Address Books from XML file using mapping file
2004-03-11 13:19:03 starlightpurple
Hi,

Is your Person class in a package? If so you will need to modify the mapping.xml file to include the package name before the class name. For example if you put the Person class in a package called MyPackage you would make the following changes to the mapping.xml file:


* change <class name="Person"> to:
<class name="MyPackage.Person">


* change <field name="persons" type="Person" collection="collection" /> to:
<field name="persons" type="MyPackage.Person" collection="collection" />
另外的还有JAXB,JAXme 等也可以做同样的事情。

数据绑定专题

http://www.ibm.com/developerworks/cn/xml/theme/x-pracdb.html

  http://www.castor.org/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值