Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Include namespace prefix in output DOM XML?

Reply
Thread Tools

Include namespace prefix in output DOM XML?

 
 
Mark McKay
Guest
Posts: n/a
 
      12-01-2004
I'm creating a DOM tree with elements containing svg, fo, xlink and
xsl elements. I'm then attempting to write it to a file. While the
local names are being written correctly, the namespace information is
being omitted. If I define

final String NS_SVG = "http://www.w3.org/2000/svg";

I'd like the output to look something like

<root xmlns:svg="http://www.w3.org/2000/svg">

<svg:svg width="372" height="452" viewBox="0 0 372 452">
<svg:rect x="10" y="10" width="352" height="432"
fill="none" stroke="black" stroke-width="2"/>
</svg:svg>

</root>

Is there a way to do this with DOM?

I'm writing it to disk with:

TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.setParameter("svg", NS_SVG);
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
"4");

DOMSource ds = new DOMSource(doc);
StreamResult sr = new StreamResult(ostream);
t.transform(ds, sr);

Mark McKay
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
removing a namespace prefix and removing all attributes not in that same prefix Chris Chiasson XML 6 11-14-2006 05:08 PM
How to declare an XML namespace prefix with DOM? Susan A. Smith Java 8 05-23-2005 09:10 PM
"static" prefix - to parallel "this" prefix Tim Tyler Java 36 12-10-2004 01:02 AM
Tag prefix and namespace heidi ASP .Net 0 11-02-2003 07:05 PM



Advertisments