[jdom-interest] Converting from DOM to JDOM

Antony Corfield Antony.Corfield at las.ox.ac.uk
Wed May 16 08:07:27 PDT 2001


Hi Philip,

I've also tried converting JDOM to DOM Element and back to JDOM Element,
which as you say works fine. However, I think the problem arises after
transforming the DOM Tree - as I see it DOMResult.getNode() returns the tree
root which is a DOM Node of type Document. By casting the Node to a Dom
Document and using domDocument.getDocumentElement() I can get hold of the
tree root as a DOM Element. As I said, I have checked the tag name is not
null - getNodeName() - but still get the same error message ie:
org.jdom.IllegalNameException: The name "null" is not legal for JDOM/XML
elements: XML names cannot be null or empty.

Any ideas, and thanks for help,

Antony

-----Original Message-----
From: philip.nelson at omniresources.com
[mailto:philip.nelson at omniresources.com]
Sent: 15 May 2001 13:47
To: Antony.Corfield at las.ox.ac.uk; jdom-interest at jdom.org
Subject: RE: [jdom-interest] Converting from DOM to JDOM


I can't duplicate your problem.  What versions of jdom, parser etc. are you
using?

Here is what I ran


    Element el = new Element("foo");
    DOMOutputter domOut = new DOMOutputter();
    org.w3c.dom.Element domElement = null;

    try {
      domElement = domOut.output(el);
    }
    catch (JDOMException e) {
      System.out.println("JDOMException");
    }

   

    org.jdom.input.DOMBuilder domBuilder = new org.jdom.input.DOMBuilder();
    org.jdom.Element jdomElement = domBuilder.build(domElement);
    System.out.println(jdomElement.getName());

> I'm converting between JDOM and DOM using DOMOutputter to produce
> org.w3c.dom.Element for input to Xalan processor which works fine.
> 
>     DOMOutputter domOut = new DOMOutputter();
>     org.w3c.dom.Element domElement = null;
> 
>     try {
>       domElement = domOut.output(jdomElement);
>     }
>     catch (JDOMException e) {
>       System.out.println("JDOMException");
>     }
> 
>     return domElement;
> 
> However, when I try converting the DOM Node, Element or 
> Document back to
> JDOM using DOMBuilder:
> 
>     DOMBuilder domBuilder = new DOMBuilder();
>     org.jdom.Element jdomElement = domBuilder.build(domElement);
> 
> I get the following error: org.jdom.IllegalNameException: The 
> name "null" is
> not legal for JDOM/XML elements: XML names cannot be null or empty.
> 
> I have checked that the DOM Node (getNodeName()) or Element 
> (getTagName())
> does indeed have a name! Is this a name space problem, or has 
> anyone found
> similar problems?
> 
> Thanks,
> 
> Antony
> 
> 
> ______________________________________________________________________
> Antony Corfield                           Java Developer JAFER Project
> 
> email: Antony.Corfield at las.ox.ac.uk       Libraries Automation Service
>   tel: +44 (01865) 284454                 99 Banbury Rd
>   fax: +44 (01865) 278275                 Oxford OX2 6JX
> ______________________________________________________________________
> 
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yo
uraddr at yourhost.com
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com



More information about the jdom-interest mailing list