XML Java Questions

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

  1. D-Dog

    D-Dog Guest

    Hi,
    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
    example:

    <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:

    transformer.setOutputPropety(OutputKeys.INDENT,"yes");
    transformer.setOutputPropety("{http://xml.apache.org/xslt}indent-amount","4");

    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.

    Dennis
    D-Dog, Mar 23, 2006
    #1
    1. Advertising

  2. D-Dog

    D-Dog Guest

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

    transformer.setOutputProperty(OutputKeys.INDENT,"yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4");

    Dennis
    D-Dog, Mar 23, 2006
    #2
    1. Advertising

  3. D-Dog

    D-Dog Guest

    Followup:

    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
    FileOutputStream(file),"utf-8"));

    Just sending in a File object directly into StreamResult caused
    problems.

    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:

    transformer.setOutputProperty(OutputKeys.INDENT,"yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4");


    Still looking for an answer to one of the original problems: ie.
    <word:/Comment>
    D-Dog, Mar 23, 2006
    #3
  4. D-Dog

    Oliver Wong Guest

    "D-Dog" <> wrote in message
    news:...
    >
    > Still looking for an answer to one of the original problems: ie.
    > <word:/Comment>


    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:
    http://www.rpbourret.com/xml/NamespacesFAQ.htm#q1_1

    - Oliver
    Oliver Wong, Mar 24, 2006
    #4
    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. Karl Bedingfield
    Replies:
    0
    Views:
    372
    Karl Bedingfield
    Aug 13, 2003
  2. HL
    Replies:
    2
    Views:
    407
  3. Replies:
    4
    Views:
    3,393
  4. Arvin Portlock
    Replies:
    0
    Views:
    141
    Arvin Portlock
    Jun 20, 2005
  5. Erik Wasser
    Replies:
    5
    Views:
    445
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page