import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
//import org.apache.crimson.jaxp.DocumentBuilderFactoryImpl;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl;
public class FormXML {
public FormXML() {
super();
}
public static void main(String[] args) {
DocumentBuilderFactory dbf = new DocumentBuilderFactoryImpl();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Node dataNode = doc.createElement("Data");
Node loanNode = doc.createElement("Loan");
Node loanValNode = doc.createTextNode(Integer.toString(98,10));
loanNode.appendChild(loanValNode);
dataNode.appendChild(loanNode);
System.err.println("###This is the dataNode###");
System.err.println(dataNode);
} catch (ParserConfigurationException e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
}
}
This snippet of code is creating an Xml node which is then printed on to console.
Here's my problem now
If i use com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl;
I get dataNode as null which should not be the case.
And if i use org.apache.crimson.jaxp.DocumentBuilderFactoryImpl; (its commented in the code fragment shown above) i get the desired output.
Why????
Just for ur conveinence
crimson.jar contains
org.apache.crimson.jaxp.DocumentBuilderFactoryImpl whereas
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl;
is in xerces.jar.