• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sridhar bvap
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really helped me to solve my issue. Thanks Karel!!!

Pons.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic