@@ -18,55 +18,59 @@ Here's a working example for the purchase order schema.
1818
19191 . Generate mappings
2020
21- ``` javascript
22- ` ` ` java -jar jsonix-full.jar -d mappings -p PO purchaseorder.xsd
23-
21+ ```
22+ java -jar jsonix-full.jar -d mappings -p PO purchaseorder.xsd
23+ ```
2424
2525Generates mappings for the ` purchaseorder.xsd ` schema in the ` mappings\PO.js ` ; mappings will be placed in the variable ` PO ` .
2626
27272 . Unmarshalling:
2828
29- // Include or require PO.js so that PO variable is available
30- // For instance, in node.js:
31- var PO = require('./mappings/PO').PO;
32-
33- // First we construct a Jsonix context - a factory for unmarshaller (parser)
34- // and marshaller (serializer)
35- var context = new Jsonix.Context([PO]);
36-
37- // Then we create a unmarshaller
38- var unmarshaller = context.createUnmarshaller();
39-
40- // Unmarshal an object from the XML retrieved from the URL
41- unmarshaller.unmarshalURL('po.xml',
42- // This callback function will be provided with the result of the unmarshalling
43- function (unmarshalled) {
44- console.log(unmarshalled.value.shipTo.name); // Alice Smith
45- console.log(unmarshalled.value.items.item[1].productName); // Baby Monitor
46- });
29+ ``` javascript
30+ // Include or require PO.js so that PO variable is available
31+ // For instance, in node.js:
32+ var PO = require (' ./mappings/PO' ).PO ;
33+
34+ // First we construct a Jsonix context - a factory for unmarshaller (parser)
35+ // and marshaller (serializer)
36+ var context = new Jsonix.Context ([PO ]);
37+
38+ // Then we create a unmarshaller
39+ var unmarshaller = context .createUnmarshaller ();
40+
41+ // Unmarshal an object from the XML retrieved from the URL
42+ unmarshaller .unmarshalURL (' po.xml' ,
43+ // This callback function will be provided with the result of the unmarshalling
44+ function (unmarshalled ) {
45+ console .log (unmarshalled .value .shipTo .name ); // Alice Smith
46+ console .log (unmarshalled .value .items .item [1 ].productName ); // Baby Monitor
47+ });
48+ ```
4749
48503 . Marshalling
4951
50- // Create a marshaller
51- var marshaller = context.createMarshaller();
52-
53- // Marshal a JavaScript Object as XML (DOM Document)
54- var doc = marshaller.marshalDocument({
55- name: {
56- localPart: "purchaseOrder"
52+ ``` javascript
53+ // Create a marshaller
54+ var marshaller = context .createMarshaller ();
55+
56+ // Marshal a JavaScript Object as XML (DOM Document)
57+ var doc = marshaller .marshalDocument ({
58+ name: {
59+ localPart: " purchaseOrder"
60+ },
61+ value: {
62+ orderDate: { year: 1999 , month: 10 , day: 20 },
63+ shipTo: {
64+ country: " US" ,
65+ name: " Alice Smith" ,
66+ street: " 123 Maple Street" ,
67+ city: " Mill Valley" ,
68+ state: " CA" ,
69+ zip: 90952
5770 },
58- value: {
59- orderDate: { year: 1999, month: 10, day: 20 },
60- shipTo: {
61- country: "US",
62- name: "Alice Smith",
63- street: "123 Maple Street",
64- city: "Mill Valley",
65- state: "CA",
66- zip: 90952
67- },
68- billTo: { /* ... */ },
69- comment: 'Hurry, my lawn is going wild!',
70- items: { /* ... */ }
71- }
72- });
71+ billTo: { /* ... */ },
72+ comment: ' Hurry, my lawn is going wild!' ,
73+ items: { /* ... */ }
74+ }
75+ });
76+ ```
0 commit comments