Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XML parsers.

843834May 16 2007
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 13 2007
Added on May 16 2007
0 comments
94 views