none
white space preservation in word xml RRS feed

  • Question

  • I am trying to write some very simple XML that word will read.

    <document><body><p><t>This line has significant       white space.</t></p></body></document>

    This partially works.  But the white space inside of the text is modified.  I have tried setting xml:space="preserve" and space="preserve" at the <document> and <t> level with no effect.  But this does not seem to work.  So how do I put text within XML where the white space within the text is preserved?

    thanks,

    J

    Monday, January 31, 2011 8:54 PM

Answers

  • I would suggest that is not the best way to learn XML!
     
    That is not WordML, and, although Word will open a file containing that xml it can't really understand it. Without any basis for understanding "space="preserve", it will be ignored.
     
    XML is a method for storing data - no more, no less. In order to have the data displayed in a certain way (with space preserved, for example), the application you use to open the file must understand the particular 'flavour' of XML you have used, which it does by looking at the schema. Without such a schema, it has no rules, and - my best guess - Word is treating it as a browser would.
     

    Enjoy,
    Tony
    www.WordArticles.com
    • Marked as answer by Bessie Zhao Tuesday, February 8, 2011 9:34 AM
    Wednesday, February 2, 2011 5:33 PM

All replies

  • Are you trying to write your own xml against your own schema, or edit Word's xml within a word document?
     

    Enjoy,
    Tony
    www.WordArticles.com
    Tuesday, February 1, 2011 10:21 AM
  • I am not using any schema.  I am in the process of learning XML and I am writing various things in XML and opening them in Word to see how they look.

    So the following XML

    <document><body><p><t>This line has NO significant white space.</t></p></body></document>

    looks as expected in word.  and the following xml

    <document><body><p><t>This line has significant       white space.</t></p></body></document>

    has whitespace stripped out.  I did a little reasearch and thought that:

    <document><body><p><t space="preserve">This line has significant       white space.</t></p></body></document>

    would preserve the white space but it does not.

    thanks,

    Jay

     

    Tuesday, February 1, 2011 7:09 PM
  • I would suggest that is not the best way to learn XML!
     
    That is not WordML, and, although Word will open a file containing that xml it can't really understand it. Without any basis for understanding "space="preserve", it will be ignored.
     
    XML is a method for storing data - no more, no less. In order to have the data displayed in a certain way (with space preserved, for example), the application you use to open the file must understand the particular 'flavour' of XML you have used, which it does by looking at the schema. Without such a schema, it has no rules, and - my best guess - Word is treating it as a browser would.
     

    Enjoy,
    Tony
    www.WordArticles.com
    • Marked as answer by Bessie Zhao Tuesday, February 8, 2011 9:34 AM
    Wednesday, February 2, 2011 5:33 PM