Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/Examples/SDO/SdoDynamic"
(New page: == Initialize the Types (Metadata) == The first thing that needs to be done in an SDO application is to set up the metadata for the Types and Properties. This is most commonly done by loa...) |
m (→Unmarshal the XML document) |
||
Line 6: | Line 6: | ||
<br>XSDHelper.INSTANCE.define(xsdInputStream, null); | <br>XSDHelper.INSTANCE.define(xsdInputStream, null); | ||
− | == Unmarshal the XML | + | == Unmarshal the XML Document == |
SDO is often used to manipulate XML data. The following code demonstrates how to unmarshal an XML document using the dynamic APIs. | SDO is often used to manipulate XML data. The following code demonstrates how to unmarshal an XML document using the dynamic APIs. | ||
Line 12: | Line 12: | ||
<br>FileInputStream xmlInputStream = new FileInputStream("../Resource/bin/Customer-data.xml"); | <br>FileInputStream xmlInputStream = new FileInputStream("../Resource/bin/Customer-data.xml"); | ||
<br>XMLDocument xmlDocument = XMLHelper.INSTANCE.load(xmlInputStream); | <br>XMLDocument xmlDocument = XMLHelper.INSTANCE.load(xmlInputStream); | ||
− | <br>DataObject customer = | + | <br>DataObject customer = xmlDocument.getRootObject(); |
== Modify the Data Objects == | == Modify the Data Objects == |
Latest revision as of 14:04, 22 October 2007
Contents
Initialize the Types (Metadata)
The first thing that needs to be done in an SDO application is to set up the metadata for the Types and Properties. This is most commonly done by loading an XML schema, although it may also be done programmatically.
Code Example
FileInputStream xsdInputStream = new FileInputStream("Example.xsd");
XSDHelper.INSTANCE.define(xsdInputStream, null);
Unmarshal the XML Document
SDO is often used to manipulate XML data. The following code demonstrates how to unmarshal an XML document using the dynamic APIs.
Code Example
FileInputStream xmlInputStream = new FileInputStream("../Resource/bin/Customer-data.xml");
XMLDocument xmlDocument = XMLHelper.INSTANCE.load(xmlInputStream);
DataObject customer = xmlDocument.getRootObject();
Modify the Data Objects
Below is an example of manipulating the Data Objects using the dynamic APIs. Note how the dynamic accessors take an XPath instead of just a property name.
Code Example
DataObject phoneNumber = DataFactory.INSTANCE.create("urn:customer-example", "phone-number");
phoneNumber.set("number-type", "home");
phoneNumber.set("value", "(613) 555-3333");
customer.getList("contact-info/phone-number").add(phoneNumber);
Marshal the Data Objects
The following code segment demonstrates how to marshal DataObjects wrapped in a commonj.sdo.helper.XMLDocument back to XML.
Code Example
XMLHelper.INSTANCE.save(xmlDocument, System.out, null);