LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Preserve XML whitespace in Excel 2003

I have a hand-made schema, which I'm trying to get Excel 2003 to treat
properly.
The problem is that Excel insists on stripping the whitespace from my
strings.
The WC3 solution is to specify xml:space="preserve" like so:
[pre]
(?xml version="1.0" encoding="UTF-8"?)
(ns1:aSchema xmlns:ns1="uri.mine" xml:space="preserve")
(myElement)
(Display) ,TEST (/Display)
(/myElement)
(/ns1:aSchema)
[/pre]

This however is not a stable XML file for Excel, since it insists on using
it's own prefixes for namespaces -- even reserved ones.
Importing the above and exporting it produces:

[pre]
(?xml version='1.0' encoding='UTF-8'?)
(ns1:aSchema ns2:space="preserve"
xmlns:ns2="http://www.w3.org/XML/1998/namespace" xmlns:ns1="uri.mine"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance")
(myElement)
(Display) ,TEST (/Display)
(/myElement)
(/ns1:aSchema)
[/pre]

This fails validation miserably -- Python's Expat barfs with
[pre]
xml.parsers.expat.ExpatError: prefix must not be bound to one of the
reserved namespace names: line 2, column 0
[/pre]
since it's smart enough to know that the namespace Excel prefixed as ns2
should not be re-prefixed.

(and the solution is not to drop namespaces -- I'm using that for version
control. Since I'm confident that the required elements for by XML will
change in the future, the schema is namespaced, so that different versions
can coexist and can be "inherited")

Moreover, the Schema that Excel generates for this XML is a complete disaster:
[pre]
The XML Map aSchema_Map contains 3 schemas.

(!-- Schema #1 named Schema3 by Excel --)
(?xml version='1.0' encoding='UTF-8'?)
(xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="uri.mine" xmlns:ns0="uri.mine"
xmlns:ns1="http://www.w3.org/XML/1998/namespace")
(xsd:import namespace="http://www.w3.org/XML/1998/namespace")(/xsd:import)
(xsd:import)(/xsd:import)
(xsd:element nillable="true" name="aSchema")
(xsd:complexType)
(xsd:sequence minOccurs="0")
(xsd:element minOccurs="0" ref="myElement")(/xsd:element)
(/xsd:sequence)
(xsd:attribute ref="ns1:space")(/xsd:attribute)
(/xsd:complexType)
(/xsd:element)
(/xsd:schema)

(!-- Schema #2 named Schema1 by Excel --)
(?xml version='1.0' encoding='UTF-8'?)
(xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3.org/XML/1998/namespace"
xmlns:ns0="http://www.w3.org/XML/1998/namespace")
(xsd:attribute name="space" type="xsd:string")(/xsd:attribute)
(/xsd:schema)

(!-- Schema #3 named Schema2 by Excel --)
(?xml version='1.0' encoding='UTF-8'?)
(xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema")
(xsd:element nillable="true" name="myElement")
(xsd:complexType)
(xsd:sequence minOccurs="0")
(xsd:element minOccurs="0" nillable="true" type="xsd:string"
name="Display" form="unqualified")(/xsd:element)
(/xsd:sequence)
(/xsd:complexType)
(/xsd:element)
(/xsd:schema)
[/pre]

WTF? Excel itself barfs trying to deal with this. You can't do this as a
single file. You can import Schema #2 into Excel. This is at best pseudocode.

I can coerce Excel into generating the (namespaceprefix):space="preserve"
from a single schema file:
[pre]
(?xml version='1.0' encoding='UTF-8'?)
(xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns.1="uri.mine.1" targetNamespace="uri.mine.1" version="$Revision: #3
$" elementFormDefault="unqualified" attributeFormDefault="unqualified")
(xsd:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="http://www.w3.org/2001/xml.xsd"/)

(xsd:element name="myElement" type="ns.1:myType"/)

(xsd:complexType name="myType")
(xsd:sequence)
(xsd:element type="xsd:string" name="Display" /)
(/xsd:sequence)
(xsd:attribute ref="xml:space" use="required" fixed="preserve"/)
(/xsd:complexType)
(/xsd:schema)
[/pre]

but this will still result in the Expat validation failu
[pre]
(?xml version='1.0' encoding='UTF-8'?)
(ns1:myElement ns2:space="preserve"
xmlns:ns2="http://www.w3.org/XML/1998/namespace" xmlns:ns1="uri.mine.1")
(Display) ,TEST (/Display)
(/ns1:myElement)
[/pre]
Note also, that this requires a cell mapped to the xml:space attribute,
with the value set to "preserve" in spite of the fact that the schema marks
it "required" and "fixed".

tl;dr Excel 2003 sucks at schemas: what schema can preserve whitespace and
still pass validation?
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chart whitespace [email protected] Charts and Charting in Excel 1 July 10th 07 03:33 PM
Excel 2003 List does not preserve border style for all rows Geetha Excel Discussion (Misc queries) 0 August 16th 06 07:22 PM
what does whitespace not allowed in this location mean and how do. garfland Excel Discussion (Misc queries) 0 April 19th 05 03:47 PM
Preserve Excel formula entry MHoffmeier Excel Discussion (Misc queries) 5 December 2nd 04 06:34 PM
trimming whitespace Jamie Martin[_2_] Excel Programming 4 September 25th 03 09:57 PM


All times are GMT +1. The time now is 06:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"