Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Create a SVG file using DOM (creating a text Element)

843834Nov 13 2001 — edited Jan 21 2003
Using JDK1.4 and DOm library, I'm creating a text element, but the method setNodeValue doesn't work.

I include an example:
-------------------------------


import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
Document doc = impl.createDocument(svgNS, "svg", null);

// get the root element (the svg element)
Element svgRoot = doc.getDocumentElement();

// set the width and height attribute on the root svg element
svgRoot.setAttributeNS(null, "width", "400");
svgRoot.setAttributeNS(null, "height", "450");

// create the text
// my problem is under !!
// --------------------------------------------
Element text = doc.createElementNS(svgNS, "text");
text.setAttributeNS(null, "x", "50");
text.setAttributeNS(null, "y", "50");

// setNodeValue: the method doesn't work !!! ????
// ---------------------------------------------------------
text.setNodeValue("Hello");

// attach the text to the svg root element
svgRoot.appendChild(text);


// the text element is attached with two attributes (X,Y) // but no value
// That produce the SVG code:
// <text x="10" y="20"/>

// but should produce this !!!!
// ====================

// <text x="10" y="20">Hello</text>



Please HELP!!
Thanks in advance :-))
Ciao

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 18 2003
Added on Nov 13 2001
6 comments
822 views