Hi all,

Another problem with DOM support:

The method getDocumentElement will generate an exception if the DOMDocument
has no root element.
It should return null in this case.

Looking into the DOMNodeHelper class shows that 

        if ( (element instanceof org.w3c.dom.Element) ) {
            return (org.w3c.dom.Element) element;
        }
        else {
            // Use DOMWriter?
            notSupported();
            return null;
        }

Will generate this exception if element  is null.

So i patched the source to return null if element is null.

I do this for all other asDOMxxx methods too.

Regards,
Henner Kollmann

============================================================================
===================================

    public static org.w3c.dom.Node asDOMNode(Node node) {
        if ( (node == null) || (node instanceof org.w3c.dom.Node) ) {
            return (org.w3c.dom.Node) node;
        }
        else {
            // Use DOMWriter?
            System.out.println( "Cannot convert: " + node + " into a W3C DOM
Node");
            notSupported();
            return null;
        }
    }
    
    public static org.w3c.dom.Document asDOMDocument(Document document) {
        if ( (document == null) ||  (document instanceof
org.w3c.dom.Document) ) {
            return (org.w3c.dom.Document) document;
        }
        else {
            // Use DOMWriter?
            notSupported();
            return null;
        }
    }
    
    public static org.w3c.dom.DocumentType asDOMDocumentType(DocumentType
documentType) {
        if ((documentType == null) ||  (documentType instanceof
org.w3c.dom.DocumentType) ) {
            return (org.w3c.dom.DocumentType) documentType;
        }
        else {
            // Use DOMWriter?
            notSupported();
            return null;
        }
    }

    public static org.w3c.dom.Text asDOMText(CharacterData text) {
        if ((text  == null) || (text instanceof org.w3c.dom.Text) ) {
            return (org.w3c.dom.Text) text;
        }
        else {
            // Use DOMWriter?
            notSupported();
            return null;
        }
    }

    public static org.w3c.dom.Element asDOMElement(Node element) {
        if ( (element == null) ||  (element instanceof org.w3c.dom.Element)
) {
            return (org.w3c.dom.Element) element;
        }
        else {
            // Use DOMWriter?
            notSupported();
            return null;
        }
    }

    public static org.w3c.dom.Attr asDOMAttr(Node attribute) {
        if ( (attribute == null) ||  (attribute instanceof org.w3c.dom.Attr)
) {
            return (org.w3c.dom.Attr) attribute;
        }
        else {
            // Use DOMWriter?
            notSupported();
            return null;
        }
    }




-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
dom4j-dev mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to