[jdom-interest] xlink in JDOM

Edelson, Justin Justin.Edelson at mtvn.com
Thu May 4 07:33:41 PDT 2006

You have to use the setAttribute method setAttribute(String, String,
Namespace) to set a namespaced attribute.

The code would look something like this:

Namespace nsXlink = Namespace.getNamespace("xlink",
e.setAttribute("href", "download.jhtml", nsXlink);

This will actually produce:
<ref xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="download.jhtml" />

To add the namespace declaration to the parent element, the code would
look like:
Namespace nsXlink = Namespace.getNamespace("xlink",
Element parent = new Element("parent");
Element e = new Element("ref");
e.setAttribute("href", "download.jhtml", nsXlink);

Which produces:
<parent xmlns:xlink="http://www.w3.org/1999/xlink">
  <ref xlink:href="download.jhtml" />

-----Original Message-----
From: jdom-interest-bounces at jdom.org
[mailto:jdom-interest-bounces at jdom.org] On Behalf Of Ollie Glass
Sent: Thursday, May 04, 2006 5:33 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] xlink in JDOM

I'm trying to make produce this element with JDOM:
<ref xlink:href="download.html"/>

How is this done? I guessed the code might look like this, but it  
doesn't work:
Element e = new Element("ref");
e.setAttribute("xlink:href", "download.html");

Sorry if this is covered elsewhere, I couldn't find an answer searching.


To control your jdom-interest membership:

More information about the jdom-interest mailing list