how to handle pre-formatted text

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Schwartz

    how to handle pre-formatted text

    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
  • Joseph J. Kesselman

    #2
    Re: how to handle pre-formatted text

    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.

    Comment

    • Peter Flynn

      #3
      Re: how to handle pre-formatted text

      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/

      Comment

      • Joseph J. Kesselman

        #4
        Re: how to handle pre-formatted text

        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

        Comment

        • David Schwartz

          #5
          Re: how to handle pre-formatted text

          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></preHTML
          tags.

          Thanks again for the input,
          David

          Comment

          • Joseph J. Kesselman

            #6
            Re: how to handle pre-formatted text

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

            Comment

            Working...