|
|
CookXml is a unique XML data binding engine in Java. It is capable mapping XML documents of desired format directly onto the corresponding object-oriented classes, essentially treating XML as a programming language instead of merely a data storage format. Therefore, it is ideal to use CookXml to write any programs that interprets XML. The tag library of CookXml is constructed dynamically at run time, andthereforeallows dynamic XML schema. The present implementation has unmarshaling part done.CookXml is free software, distributed under a permissive, X11 style licence. Unmarshaling
CookXml offers the ability to directly mapping XML documents onto existing classes by breaking down the process into three general steps. Then use a set of delegates, together forming a tag library, to handle actions performed at these steps.Object creation. Each element tag corresponds to an object instance. The action to create the object instance corresponds to a creator in CookXml.Property setting. Each attribute of the XML element corresponds to setting a property of the object instance. This property can be handled by a setter in CookXml. For languages that offer reflection, such as Java and C#, such property setting can be automatically detected using reflection. In these cases, to match the string attribute value to the target property class type, a converter is necessary.Add action. When CookXml obtains an object corresponding to an element tag, it is "added" to the parent object corresponding to the parent element tag. The specific add action is handled by an adder in CookXml.Save for CDATA nodes, the three above types of actions can handle all elements in an XML document. CDATA in general can be handled either in the creator function or the adder function.Creators, setters, adders, and converters together form a tag library which is used by the CookXml engine to perform the XML data binding. Dynamic Tag Library Construction
Because CookXml tag library uses delegates, its tag library needs to be dynamically constructed. This feature is both good and bad. It is bad because there will be a slight initiation cost when the tag library is constructed, and its integrity may not be verified until runtime. It is also good because it allows developers to easily extend an existing tag library at run time. Preorder and Postorder Addition
Like any trees that can be traversed in preorder and postorder, the object corresponding to an XML element can be added to the parent object in preorder or postorder. In the preorder addition, the object is added to the parent before descendant XML elements get processed. In the postorder addition, the object is added to the parent after descendant XML elements get processed. XML Tag Inheritance
One discovery made while writing CookXml was that class inheritance of Object-oriented languages can be mirrored into XML element tag inheritance. Semantically, tag inheritance means that the derived tag will inherit the setters and adders of the inherited tags.For example, javax.swing.JMenu is a child class of javax.swing.JMenuItem. Assuming that javax.swing.JMenu is mapped to
Related Ads
|
|