XML Java Questions

Discussion in 'Java' started by D-Dog, Mar 23, 2006.

  1. D-Dog

    D-Dog Guest

    I'm just getting started with XML and have been trying to write out
    my xml document to a file. The data itself looks correct, but I have
    two formatting questions:

    1. Each tag has a 'word:' appended to the beginning of it. For

    <word:Comment> ............................. </word:Comment>

    How do I remove the 'word:' from the front of each tag? It's like that
    for all of them.

    2. Try as I might, I have not been able to get indenting to work.
    I've searched the net in vain, and all tell me to set the following
    properties on my transformer:


    Unfortunately, all of the tags continue to be lined up along the left
    side with no indenting. Am I missing something? I snipped out the
    rest of the code that sets up the transformer so as not to clutter this
    post, but if you need more info, I will repost it.

    Thank you very much for any help you can provide.

    D-Dog, Mar 23, 2006
    1. Advertisements

  2. D-Dog

    D-Dog Guest

    Sorry, a typo in those setOutputProperty lines... Should read:


    D-Dog, Mar 23, 2006
    1. Advertisements

  3. D-Dog

    D-Dog Guest


    After some more research, I located a bug report against java 1.5.0_04
    that had to do with the indenting problem. There were two things that
    needed to be done to workaround:

    1. Wrap the output stream with a writer OutputStreamWriter , so the
    StreamResult would look something like:

    File file = new File(filename);
    Result result = new StreamResult(new OutputStreamWriter(new

    Just sending in a File object directly into StreamResult caused

    2. Set the transformerFactory attribute to something like:

    transformFac.setAttribute("indent-number", new Integer(2));

    After both of these are setup, the previous two lines remain unchanged:


    Still looking for an answer to one of the original problems: ie.
    D-Dog, Mar 23, 2006
  4. D-Dog

    Oliver Wong Guest

    I don't know the specific API you're working with, but here's a generic
    FAQ on XML Namespaces that might help you focus your search:

    - Oliver
    Oliver Wong, Mar 24, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.