You need to consult the truly marvelous table in the org.w3c.dom.Node documentation. There you will find that Document elements and Element objects return null as the nodeValue() - that is why your output says "null" Your Document is getting created, you are just using the wrong method to look at it.