This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes creating xml file using JDOM having xml:lang Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "creating xml file using JDOM having xml:lang" Watch "creating xml file using JDOM having xml:lang" New topic
Author

creating xml file using JDOM having xml:lang

ashwin vulugundam
Greenhorn

Joined: Jul 22, 2011
Posts: 16
my requirement was to creat a xml file for BOOK.
the xml file looks like below
<Book>
<author></author>
</Book>

Now my requirement changed i want to have language(which is xml:lang) as attribute for Book element.
i used some code like this
Element e= new Element("Book");
e.setAttribute("xml:lang","en");

Since i have compulsion to use JDOM.

I am getting following exception
An exception occurred: org.jdom.IllegalNameException colan cannot be used.

Later i searched jdom documentation .

there was statement which goes like this
If you're trying to create the xml:lang and xml:space attributes use:

Element e =
new Element("lang", Namespace.XML_NAMESPACE);


i followed the same but did get same exception.
later i created the namespace which has xml:lang attribute
Namespace ns1 = Namespace.getNamespace("namespace","http://www.w3.org/XML/1998");
lement catalogue =new Element("Book");
catalogue.setAttribute("xml:lang","en",ns1.XML_NAMESPACE);

But i am not able to get it right.
Any suggestion ??
ashwin vulugundam
Greenhorn

Joined: Jul 22, 2011
Posts: 16
ok i got the solution i used the following way:
Namespace nsp = Namespace.getNamespace("xml","http://www.w3.org/XML/1998/namespace");
Element catalogue =new Element("Book");

catalogue.setAttribute("lang", "de",nsp);

thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: creating xml file using JDOM having xml:lang
 
Similar Threads
Soap Fault Implementation
How would do you handle this?
Name space recurring in each element of output XML
xml:lang and XML Schema
Facing problem with JAXB1.0