javascript代码实例教程-jibx进行xml数据绑定的binging.xml配置

发布时间:2019-03-02 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-jibx进行xml数据绑定的binging.xml配置脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。 1、给一个例子:

 

<binding XMlns:ns1="https://vteba.COM/service/xML/jibx" name="bind" package="com.vteba.service.xml.jibx">

  <namespace uri="https://vteba.com/service/xml/jibx" default="elements"/>

  <;mapping abstract="true" tyPE-name="ns1:customer" class="com.vteba.service.xml.jibx.Customer">

    <structure map-as="ns1:person" field="person" usage="optional" name="person"/>

    <value style="element" name="street" field="street" usage="optional"/>

    <value style="element" name="cITy" field="city" usage="optional"/>

    <value style="element" name="state" field="state" usage="optional"/>

    <value style="attribute" name="zip" field="zip" usage="optional"/>

    <value style="element" name="phone" field="phone" usage="optional"/>

    <collection field="nameList" usage="optional" create-type="java.util.ArrayList">

      <value name="name" type="java.lang.String"/>

    </collection>

    <collection field="personList" usage="optional" create-type="java.util.ArrayList">

      <structure map-as="ns1:person" name="person"/>

    </collection>

  </mapping>

  <mapping class="com.vteba.service.xml.jibx.Customer" name="customer">

    <structure map-as="ns1:customer"/>

  </mapping>

  <mapping abstract="true" type-name="ns1:person" class="com.vteba.service.xml.jibx.Person">

    <value style="attribute" name="customerNumber" field="customerNumber"/>

    <value style="element" name="FirstName" field="firstName" usage="optional"/>

    <value style="element" name="lastName" field="lastName" usage="optional"/>

  </mapping>

</binding>

2、这个文件是使用jibx提供的工具生成。不用手工去写了。当然你可以参考jibx提供的20多个例子来写。

 

jibx工具类,org.jibx.binding.generator.BindGen或org.jibx.binding.BindingGenerator这两个类都可以,前者在jibx-tools.jar

 

中,后者在jibx-bind.jar中。

 

 

3、命令 

 

 

 

4、当然你可以把这些命令写在ant脚本中,或者使用java main方法来执行。此处直接使用命令行。

 

我使用的是maven,在命令行中切换到target文件夹下的classes目录。

 

上面的java 是运行某个程序 –cp是依赖的classpath路径的jar、zip等文件,-b 是输出文件名称,是BindGen类的参数。这样会在classes目录中生成bind.xml文件和jibx.xsd文件。bind.xml既是开头贴出来的文件。

 

 

5、然后你可以通过上述bind.xml文件,对jibx类进行字节码增强。

 

有两种方式可以使用,一是使用ant,官方提供了很多例子,可以自己参考写。

 

二是是jibx eclipse maven插件。会自动绑定,推荐使用这个。可以到网上去下载

 

 

 

上面还有一个jibx.xsd文件,可以根据他产生java类。

 

 

 

6、下面既是使用类

 

package com.vteba.service.xml.jibx;

 

import java.util.List;

 

public class Customer {

public Person person;

public String street;

public String city;

public String state;

public Integer zip;

public String phone;

public List<String> nameList;

public List<Person> personList;

 

public Person getPerson() {

return person;

}

 

public void setPerson(Person person) {

this.person = person;

}

 

public String getStreet() {

return street;

}

 

public void setStreet(String street) {

this.street = street;

}

 

public String getCity() {

return city;

}

 

public void setCity(String city) {

this.city = city;

}

 

public String getState() {

return state;

}

 

public void setState(String state) {

this.state = state;

}

 

public Integer getZip() {

return zip;

}

 

public void setZip(Integer zip) {

this.zip = zip;

}

 

public String getPhone() {

return phone;

}

public void setPhone(String phone) {

this.phone = phone;

}

 

public List<Person> getPersonList() {

return personList;

}

 

public void setPersonList(List<Person> personList) {

this.personList = personList;

}

 

public List<String> getNameList() {

return nameList;

}

 

public void setNameList(List<String> nameList) {

this.nameList = nameList;

}

 

}

 

public class Person {

public int customerNumber;

public String firstName;

public String lastName;

 

 

public int getCustomerNumber() {

return customerNumber;

}

 

 

public void setCustomerNumber(int customerNumber) {

this.customerNumber = customerNumber;

}

 

 

public String getFirstName() {

return firstName;

}

 

 

public void setFirstName(String firstName) {

this.firstName = firstName;

}

 

 

public String getLastName() {

return lastName;

}

 

 

public void setLastName(String lastName) {

this.lastName = lastName;

}

}

 

7、这个例子已经包含了,一般类的映射,List<JavaBean> List<String>。

 

如果将 List<String> 换成String[], create-type属性就不需要指定了。

 

 

关于绑定文件的各个属性的意思,请参考官方文档。attribute是作为属性,element是作为子元素。

 

对于collection,如果不指定name属性,映射的xml将不会有最外层元素。

 

觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的javascript代码实例教程-jibx进行xml数据绑定的binging.xml配置全部内容,希望文章能够帮你解决javascript代码实例教程-jibx进行xml数据绑定的binging.xml配置所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。