tailieunhanh - Java & XML 2nd Edition solutions to real world problems phần 10

Với Thư viện Foobar cho phép truy cập vào một danh sách XML của cuốn sách mới của nó, di chuyển gần hơn đến mục tiêu cung cấp nội dung up-to-ngày cho khách hàng của nó. Ngoài ra, đã có một tiêu chuẩn được thiết lập để sử dụng Java cho phát triển ứng dụng. | Java XML 2nd Edition xml version xml-java-binding-schema version options package element name catalog type class root true xml-java-binding-schema Now generated source will be placed in the javaxml2 jaxb directory with the same structure as the package hierarchy. Next let s specify that the level attribute on the item element should be a number instead of the default a String xml version xml-java-binding-schema version options package element name catalog type class root true element name item type class attribute name level convert int element xml-java-binding-schema As you can see I first added an element declaration for the item element. This allows me to reference its level attribute using the attribute construct. To handle the datatype I specified the type I wanted int with the convert attribute. Continuing with the options that a binding schema supplies here s a really nice feature. You can actually change the name of a property from what it is in the DTD. For example I hate methods like getId . Instead I really prefer getID which looks much better. So what I really want is to name the id property from my DTD as ID in Java. This turns out to be simple with JAXB xml version xml-java-binding-schema version options package element name catalog type class root true element name item type class attribute name level convert int attribute name id property ID element xml-java-binding-schema Once you ve made all of these various changes run the schema compiler xjc again. You ll get the modified classes I ve been talking about and now can compile those javac -d . javaxml2 jaxb .java If you have any problems ensure that you still have in your classpath. There are quite a few more options for the binding schema than those discussed here in fact many of these were undocumented and I found them by looking at the included with JAXB. I suggest you do the same in addition to .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.