0

I try to do example code

public class xml_class {
    /**
     * Unmarshal the sample document from a file, compute and set order total, then
     * marshal it back out to another file.
     *
     * @param args
     */
    public static void main(String[] args) {
        try {

            // unmarshal customer information from file
            IBindingFactory bfact = BindingDirectory.getFactory(test.Order.class);
            IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
            FileInputStream in = new FileInputStream("D:/liferay-develop/data1.xml");
            Order order = (Order)uctx.unmarshalDocument(in, null);

            // compute the total amount of the order
            float total = 0.0f;
            for (Iterator<Item> iter = order.getItems().iterator(); iter.hasNext();) {
                Item item = iter.next();
                total += item.getPrice() * item.getQuantity();
            }
            order.setTotal(new Float(total));

            // marshal object back out to file (with nice indentation, as UTF-8)
            IMarshallingContext mctx = bfact.createMarshallingContext();
            mctx.setIndent(2);
            FileOutputStream out = new FileOutputStream("D:/liferay-develop/out.xml");
            mctx.setOutput(out, null);
            mctx.marshalDocument(order);
            System.out.println("Processed order with " + order.getItems().size() +
                " items and total value " + total);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (JiBXException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}

And get an error:

Unable to access binding information for class test.Order
Make sure the binding has been compiled
java.lang.NoSuchFieldException: JiBX_bindingList
at java.lang.Class.getDeclaredField(Unknown Source)
at org.jibx.runtime.BindingDirectory.getBindingList(BindingDirectory.java:68)
at org.jibx.runtime.BindingDirectory.getFactory(BindingDirectory.java:211)
at test.xml_class.main(xml_class.java:31)

What is binding? And how to use it?

2
  • Binding defines how your XML structure corresponds to your Java object. I think that JiBX's binding tutorial is a good place to start. Aug 13, 2012 at 9:05
  • Im watch them but, my english terrible and its hard to me read so much text. I try Eclipse JiBX plugin. But nothing is changed.
    – Kliver Max
    Aug 13, 2012 at 9:18

1 Answer 1

2

Eli, Why don't you start with a simple example. Here is a nice one to start with: https://github.com/jibx/maven-plugin/tree/master/test-suite/base-binding-test Check this out, build it, and run the simple marshalling/unmarshalling example in the org.jibx.schema.test.person project. I hope this helps. Don

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.