Include namespace prefix in output DOM XML?

Discussion in 'Java' started by Mark McKay, Dec 1, 2004.

  1. Mark McKay

    Mark McKay Guest

    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
     
    Mark McKay, Dec 1, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Tyler
    Replies:
    36
    Views:
    1,482
    Darryl L. Pierce
    Dec 10, 2004
  2. Susan A. Smith
    Replies:
    8
    Views:
    26,152
  3. Laurens

    XML Schema namespace prefix?

    Laurens, Jan 2, 2004, in forum: XML
    Replies:
    1
    Views:
    427
    Martin Honnen
    Jan 2, 2004
  4. Thea
    Replies:
    6
    Views:
    2,030
  5. Chris  Chiasson
    Replies:
    6
    Views:
    627
    Richard Tobin
    Nov 14, 2006
Loading...

Share This Page