[jdom-interest] Adding attributes which contain colons to root element

Phil Weighill Smith phil.weighill-smith at volantis.com
Mon Jul 25 03:08:42 PDT 2005


You should:

      * use JDOM's Namespace objects
      * use "new Element(String name, Namespace namespace)"
      * use "element.addNamespaceDeclaration()" for xmlns:asi and
        xmlns:xsi
      * use "element.setAttribute(String name, String value, Namespace
        namespace)" for xsi:schemaLocation

Phil :n)

On Fri, 2005-07-22 at 13:47 -0400, Black, Henry wrote:
> I am using XML and JDOM for the first time, and want to build a
> document using:
> 
>  
> 
>       Element root = new Element("myReport");
> 
>       Document doc = new Document(root);
> 
>  
> 
> Then I want to add attributes for namespace and schema
> 
>  
> 
>       root.setAttribute("xmlns:asi",
> 
>                         http://www.broken.com/asi)
> 
>       root.setAttribute("xsi:schemaLocation",
> 
>                          "C:/config/myReport.xsd");
> 
>  
> 
> This results in an error which states:  "Attribute names cannot
> contain colons."
> 
>  
> 
> I think I can deal with the namespace by assigning the namespace when
> I build each element.  I have not figured out how to assign a schema
> location without using the SAXBuilder class to build my document.
> That option seems to require that I have a physical xml file, which I
> don't need.
> 
>  
> 
> Suggestions?
> 
>  
> 
> Thanks.
> 
>  
> 
>      - Henry
> 
> 


More information about the jdom-interest mailing list