Dom by Kamalakar Dandu
Dom by Kamalakar Dandu
Dom by Kamalakar Dandu
Why DOM
ensures proper grammar and wellformedness. The DOM abstracts content away from grammer. simplifies internal document manipulation. Mirrors typical hierarchical and relational database structures
DOM Level 2
Specification currently has the status of candidate Recommendation this means that it has received significant review from its immediate technical community, and now requires implementation and technical feedback from parties external to the W3C.
private Element createElement(Document doc,Node parent,String name, String value) { Element elem=doc.createElement(name);
private Attr createAttribute(Document doc, Element element, String attrName, String attrValue) { Attr attr = null; if(attrName != null) attr = doc.createAttribute(attrName);
if(attrValue!=null) attr.setValue(attrValue); if(element != null && attr!=null) element.setAttributeNode(attr); return attr; Example : CreateEmpXML.java
Exercise
Product.xml stores below information
Quantity
5 3 6
Write the below programs : 1. Add a new product to the list 2. Update the product price and quantity Reference : DOMReaderDemo.java, ProductDemo.java Note : The Changes made to the Product XML need not be recorded. You are only required to store the changes in DOM tree and display the same.
The factory must configured, and the appropriate error handler set. The document must be associated with at least one schema, and possibly more.
To specify the schema definition in the document, you would create XML like this:
<documentRoot xmlns:xsi=http://www.w3.org/2001/XMLSchemainstance
xsi:noNamespaceSchemaLocation=YourSchem aDefinition.xsd > ...
XSD : Greeting.xsd