Excel-Friendly XML Schemas


Several characteristics make an XML schema more amenable to being mapped into Excel. First, an XML schema should have one root element. In our example in this chapter, the root element is Order. If a schema supports more than one root element, you must choose which element will be the root element when adding the XML map to the spreadsheet.

Unsupported XML Schema Constructs

Excel does not support several XML schema constructs. Table 21.1 lists these constructs.

Table 21.1. XML Schema Constructs That Are Not Supported by Excel

Construct

What It Does

<any>

Allows you to include arbitrary elements that are not declared by the schema.

<anyAttribute>

Allows you to include arbitrary attributes that are not declared by the schema.

recursion

A structure that refers to itself recursively.

abstract elements

Allows an element to be declared but never usedalso uses substitution to substitute other elements for the abstract element.

<substitutionGroup>

Allows an element to be substituted for another element.

mixed content

When XML elements are intermixed with non-XML elements. This proves to be very useful for Word XML mapping.


Constructs That Can Be Mapped But Not Exported

There are also several things that can be mapped, but the generated mappings cannot be exported as XML. You have already seen that if an XML mapping is denormalized, it cannot be exported. You also cannot export a list of items containing a second list of items. Choice elements also cannot be exported.

The other general class of issues that prevents exporting is when a mapped element's relationship with another element it is related to cannot be preserved by the mapping. For more information on these types of mapping issues, consult the Excel documentation.

VSTO-Friendly Schemas

VSTO puts some additional requirements on schema mapping if you want to use a schema-mapped spreadsheet with VSTO. First, you need to have a schema mapping that can be exported. Second, all the schema mapping must be within a single worksheet. Although Excel will let you map some elements of the schema to Sheet1 and other elements to Sheet2, VSTO requires that all schema mapping for a given schema be on the same sheet.

How XML Schema Data Types Are Mapped to Excel Cell Formats

As you saw earlier in this book when mapping dates, Excel can automatically pick cell formatting based on the type in the schema. When we dragged a date into Excel, Excel prompted to change the cell formatting. Table 21.2 shows how Excel maps schema types to Excel cell-formatting settings.

Table 21.2. XML Schema Types and Their Corresponding Excel Cell Formatting

XML Type

Excel Formatting

anytype

Text

anyURI

Text

base64Binary

Text

boolean

Boolean

byte

General

date

Date *3/14/2001

dateTime

m/d/yyyy h:mm

decimal

General

double

General

duration

Text

ENTITIES

Text

ENTITY

Text

float

General

gDay

Number, no decimals

gMonth

Number, no decimals

gMonthDay

Custom d-mmm

gYear

Number, no decimals

gYearMonth

Custom mmm-yy

hexBinary

Text

ID

Text

IDREF

Text

IDREFS

Text

int

General

integer

General

language

Text

long

General

Name

Text

NCName

Text

negativeInteger

General

NMTOKEN

Text

NMTOKENS

Text

nonNegativeInteger

General

nonPositiveInteger

General

normalizedString

Text

NOTATION

Text

positiveInteger

General

QName

Text

short

General

string

Text

time

h:mm:ss

token

Text

unsignedByte

General

unsignedInt

General

unsignedLong

General

unsignedShort

General





Visual Studio Tools for Office(c) Using Visual Basic 2005 with Excel, Word, Outlook, and InfoPath
Visual Studio Tools for Office: Using Visual Basic 2005 with Excel, Word, Outlook, and InfoPath
ISBN: 0321411757
EAN: 2147483647
Year: N/A
Pages: 221

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net