how to handle pre-formatted text

Discussion in 'XML' started by David Schwartz, Apr 15, 2008.

  1. I've got some pre-formatted text and I'm not sure how to encode it in
    my xml to preserve its formatting. Any help would be appreciated!

    TIA,
    David
    David Schwartz, Apr 15, 2008
    #1
    1. Advertising

  2. David Schwartz wrote:
    > I've got some pre-formatted text and I'm not sure how to encode it in
    > my xml to preserve its formatting. Any help would be appreciated!


    How is the formatting currently recorded?

    If by "pre-formatted" you mean it contains spaces and tabs and
    line-breaks -- that's no problem; basic XML considers all of that
    meaningful content and will retain it. Individual XML applications may
    discard some of this whitespace, perhaps based on schema and perhaps
    based simply on their understanding of how that particular kind of XML
    document should be interpreted... but that's a matter of how the XML is
    used, not what it contains.

    Exception: Whitespace and line breaks in attribute values will be
    normalized. See the XML Recommendation for details.

    If a particular tool doesn't retain information you need, it may not be
    the right tool for your tasks, or you may not be using it right. To take
    a specific example: XHTML, when displayed by a browser, will be
    processed as HTML was and most whitespace will be discarded unless it is
    in element specifically designed or marked to retain the existing
    formatting. But that's the browser's behavior, and conventions of the
    use of the XHTML markup, not XML.

    If by "pre-formatted" you mean something else, please clarify.
    Joseph J. Kesselman, Apr 15, 2008
    #2
    1. Advertising

  3. David Schwartz

    Peter Flynn Guest

    David Schwartz wrote:
    > I've got some pre-formatted text and I'm not sure how to encode it in
    > my xml to preserve its formatting. Any help would be appreciated!


    It depends on the features provided by whatever schema/dtd you are using
    (if any). Some (eg DocBook) provide markup specifically designed to
    contain data that requires the preservation of linebreaks, for example.
    Others (eg XHTML) provide a container (pre) but the recommendation about
    how to handle it is in the spec, not the markup.

    Without a schema/dtd, the only facility is a CDATA section within some
    suitable element, but this is intended for the preservation of otherwise
    parsable *markup* characters, not space-and-newline formatting, so you'd
    need to specify or convey to anyone using it exactly what they should or
    should not do with it.

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
    Peter Flynn, Apr 16, 2008
    #3
  4. As far as XML is concerned, CDATA sections are just an alternative to
    character-by-character escaping -- in other words, they're just syntax,
    not semantics. They won't change how whitespace is interpreted, and they
    may not even be visible to applications and/or may not be preserved
    through stages of XML processing. So that approach isn't worth pursuing.

    If you want to preserve whitespace, you need an element that your
    particular application code doesn't process by discarding whitespace. As
    I said, this is an application issue, not an XML issue per se... though
    XML can provide some hints that the application may or not respect, such
    as the xml:space attribute.

    See http://www.w3.org/TR/REC-xml/#sec-white-space
    Joseph J. Kesselman, Apr 16, 2008
    #4
  5. Thanks for the responses. The content is just some CSS style
    definitions.

    For some reason, pasting the formatted content into the tool I'm using
    (Turbo XML) resulted in it being pretty messed up. Editing the content
    in a normal text editor to ensure that everything's lined up properly
    led to the desired result. Also, the changes seemed to be preserved
    after going back into the xml editor.

    FYI, I'm just placing content within the xml tag into <pre></pre> HTML
    tags.

    Thanks again for the input,
    David
    David Schwartz, Apr 16, 2008
    #5
  6. David Schwartz wrote:
    > For some reason, pasting the formatted content into the tool I'm using
    > (Turbo XML) resulted in it being pretty messed up.


    That sounds like a question of how cut and paste are working with your
    tools -- how much non-text data the cut is capturing, and how good Turbo
    XML is at figuring out how to discard it and just take the plaintext
    view. Contact its authors and ask them...
    Joseph J. Kesselman, Apr 16, 2008
    #6
    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. Rocky Moore
    Replies:
    7
    Views:
    1,719
    mikeb
    Jan 14, 2004
  2. Wladimir Borsov
    Replies:
    7
    Views:
    463
    Raymond Loman
    May 5, 2004
  3. =?ISO-8859-1?Q?KLEIN_St=E9phane?=
    Replies:
    3
    Views:
    441
    hanumizzle
    Oct 6, 2006
  4. John Kotuby
    Replies:
    2
    Views:
    1,567
    John Kotuby
    Jan 28, 2008
  5. GriffithsJ

    Pre-formatted text

    GriffithsJ, Feb 3, 2004, in forum: ASP General
    Replies:
    2
    Views:
    144
    Chris Barber
    Feb 3, 2004
Loading...

Share This Page