Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes How to use org.jdom.NameSpace in setAttribute() method of org.jdom.Element? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to use org.jdom.NameSpace in setAttribute() method of org.jdom.Element?" Watch "How to use org.jdom.NameSpace in setAttribute() method of org.jdom.Element?" New topic
Author

How to use org.jdom.NameSpace in setAttribute() method of org.jdom.Element?

sridhar bvap
Greenhorn

Joined: Mar 12, 2008
Posts: 19
Hi to all,

Iam building xml file.In that iam trying to create org.jdom.NameSpace in setAttribute() method of org.jdom.Element object. Iam getting runtime errors like illegal name.
What exactly i want is i want to set "xmlns" as attribute name and "http://www.loc.gov/MARC21/slim" as attribute value. When iam directly creating that it is throwing exception that no attribute name should be xmlns in org.jdom.Element. That is why i approched to org.jdom.NameSpace. But iam not getting the way, how to set org.jdom.NameSpace in setAttribute method of org.jdom.Element object. I tried several ways but it is not comming.
can any budy help me please.
thanks to one and all.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

Well, let's get the terminology straight for a start. When you see this in an XML document:that is called a namespace declaration. It's not an attribute, although in some DOM implementations you can cheat and use an attribute to create one.

Usually you don't explicitly put a namespace declaration into your XML. You usually do it indirectly, by using the namespace URI as part of the name of an element or an attribute.

Okay, now that we have done that, can you tell us what you are trying to do? It appears you are confused by namespaces and are trying to do something the wrong way, but it's hard to tell.
Philippe Desrosiers
Ranch Hand

Joined: Mar 29, 2006
Posts: 138
I'm having the exact same problem (with JDOM). Basically, I'm trying to set the (so-called) "default namespace" uri, like so:

There doesn't seem to be any way to do this in JDOM...

any ideas?
Karel Havlicek
Greenhorn

Joined: Dec 15, 2008
Posts: 3
Hi, this simple xmlns cut be taken e.g. as :

Namespace XSI_NAMESPACE = Namespace.getNamespace("", "http://www.w3.org/2000/10/XMLSchema-instance");
yourRootElement.setNamespace(XSI_NAMESPACE);
Ponnusamy Gov
Greenhorn

Joined: Feb 01, 2011
Posts: 17
Really helped me to solve my issue. Thanks Karel!!!

Pons.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use org.jdom.NameSpace in setAttribute() method of org.jdom.Element?