| 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
|
 |
 |
|
|
subject: creating xml file using JDOM having xml:lang
|
|
|