hi,
  Here's an example of how I did it.  Might not be the best way, but it
works:
(just a exerpt, a method that returns a text containing element):

    /** Text is special because you have to not only create a "text"
Element, you have to append a child Text node which is the piece that
actually has the text you want to see.
      *
      * @param idStr  sets an id to the element
      * @param someText
      * @param x  x position
      * @param y  y position
      * @return Returns an Element which contains some text to be
displayed.
      */
     public Element svg_TextElement(String idStr, String someText, int
x, int y) {
// theDoc refers to the Document containing the DOM
         Element text =
theDoc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "text");
         text.appendChild(theDoc.createTextNode(someText));
         text.setAttributeNS(null, "id", idStr);
         text.setAttributeNS(null, "x", Integer.toString(x));
         text.setAttributeNS(null, "y",Integer.toString(y));
// optionally set the textLength
         text.setAttributeNS(null, "textLength",
Integer.toString(someText.length())+"em");
         return text;
     }


 ...really the key line is just;
         text.appendChild(theDoc.createTextNode(someText));

-Randyc

-----Original Message-----
From: Todd O'Bryan [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 07, 2004 10:44 AM
To: [EMAIL PROTECTED]
Subject: Text element


Stupid newbie question:

How do I create a <text> element using the DOM API?

I teach high school and one of my advanced students is trying to do 
text display in SVG, but neither of us can figure out how to do it 
programmatically with the DOM. We understand that

<text x="10" y="20">my pretty text</text>

should be all we need, but we can't figure out how to get the "my 
pretty text" into the element. (After lots of previous work with JDOM, 
I expected to find a setContent() or setText() method somewhere in the 
Element hierarchy, but darned if it's not there.

If someone could provide a real simple example in the flavor of the 
rectangle example at

http://xml.apache.org/batik/domapi.html

my student and I would both be very grateful.

Thanks,
Todd


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to