office open xml developer workshop custom xml integrating data and documents
TRANSCRIPT
Office Open XML Developer Workshop
Custom XMLCustom XMLIntegrating data and documents
Office Open XML Developer Workshop
DisclaimerDisclaimerThe information contained in this slide deck represents the current view of Microsoft Corporation on the issues discussed as of the date of
publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication.
This slide deck is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT.
Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this slide deck may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this slide deck. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this slide deck does not give you any license to these patents, trademarks, copyrights, or other intellectual property.
Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, email address, logo, person, place or event is intended or should be inferred.
© 2006 Microsoft Corporation. All rights reserved.Microsoft, 2007 Microsoft Office System, .NET Framework 3.0, Visual Studio, and Windows Vista are either registered trademarks or
trademarks of Microsoft Corporation in the United States and/or other countries.The names of actual companies and products mentioned herein may be the trademarks of their respective owners.
Office Open XML Developer Workshop
Why Custom XML?Why Custom XML?
Enables interoperability with other systemsDocuments can provide a rich view of back-end data sourcesDocuments can update back-end data sources
Exposes business data in Open XML documentsHeterogenous systems can easily read data from documentsBusiness-specific semantics can be applied to document data
Separates presentation and dataSimplified programming model for all of the above
Custom XML schema support was a key design objective for Open XML: any schema can be used in Open XML documents.
Office Open XML Developer Workshop
Custom XML: Developer OptionsCustom XML: Developer Options
Office Open XML Developer Workshop
CUSTOM XML PARTSCUSTOM XML PARTS
Office Open XML Developer Workshop
Custom XML PartsCustom XML Parts
Pure custom data: only your tags appear in the part
Format-agnosticWordprocessingML: relationship from main documentSpreadsheetML: relationship from workbookPresentationML: relationship from presentation or slide
Explicit relationship from a shape on a slide
No content restrictions: any schema (or none), any number of partsSyntactical restriction: must contain well-formed XML
Office Open XML Developer Workshop
Custom XML Part: Properties/MetadataCustom XML Part: Properties/Metadata
Information about a custom XML part is stored in a custom XML properties partStored via an implicit customXmlProps relationship from the custom XML part
Contains two types of information:Part ID
Uniquely identifies a part within a documentMaintained through editing sessionsOffice uses GUIDs, you can use any type of unique identifier
XML Schema references DEMO
Office Open XML Developer Workshop
STRUCTURED DOCUMENT TAGSSTRUCTURED DOCUMENT TAGS
Office Open XML Developer Workshop
Structured Document TagsStructured Document Tags
Smart tags and custom XML markup add semantics, but do not have any effect on presentationSometimes you want to affect presentation
Custom UI behaviors: data-entry restrictions, multi-select, etc.
The solution: the structured document tag <sdt>
Office Open XML Developer Workshop
Structured Document TagsStructured Document Tags
A structured document tag has two sections:
SDT properties
SDT content
Office Open XML Developer Workshop
Structured Document Tag Properties <sdtPr>Structured Document Tag Properties <sdtPr>
Generic properties: Type, Title, ID, placholder textType-specific properties
Example: values for populating a dropdown list
Runtime behaviors (locking properties)Whether region is editableWhether region is deletable
<w:sdtPr> <w:id w:val="865823534" /> <w:placeholder> <w:docPart w:val="DefaultPlaceholder_22675703" /> </w:placeholder> <w:showingPlcHdr /> <w:dataBinding w:prefixMappings="xmlns:ns0='http://myschemas/thisone'" w:xpath="/ns0:Customer[1]/ns0:Name" w:storeItemID="myCustomXmlDataIdentifier" /> <w:text /> </w:sdtPr>
<w:sdtPr> <w:id w:val="865823534" /> <w:placeholder> <w:docPart w:val="DefaultPlaceholder_22675703" /> </w:placeholder> <w:showingPlcHdr /> <w:dataBinding w:prefixMappings="xmlns:ns0='http://myschemas/thisone'" w:xpath="/ns0:Customer[1]/ns0:Name" w:storeItemID="myCustomXmlDataIdentifier" /> <w:text /> </w:sdtPr>
Office Open XML Developer Workshop
Other Control TypesOther Control Types
In addition to plain text:Rich TextDate PickerPictureComboboxDropdown ListDocument Building Block
Office Open XML Developer Workshop
DATA BINDINGDATA BINDING
Office Open XML Developer Workshop
Data Binding: Bringing It All TogetherData Binding: Bringing It All Together
2-way synchronization between:
Content controls (data in structured document tags)Custom XML nodes (data in your schema)
Office Open XML Developer Workshop
Data Binding SyntaxData Binding Syntax
<dataBinding> element inside <sdtPr>
<w:dataBinding w:prefixMappings="xmlns:ns0='http://myschemas/thisone'" w:xpath="/ns0:Customer[1]/ns0:Name" w:storeItemID="myCustomXmlDataIdentifier"/><w:dataBinding w:prefixMappings="xmlns:ns0='http://myschemas/thisone'" w:xpath="/ns0:Customer[1]/ns0:Name" w:storeItemID="myCustomXmlDataIdentifier"/>
Office Open XML Developer Workshop
Data Binding BasicsData Binding Basics
To bind a custom Xml node to a structured document tag:Add a <dataBinding> element to the structured document tag properties <sdtPr><dataBinding> specifices a custom Xml part (by Custom XML Data Identifier) and an Xpath to a specific node within that part
Custom XML Data Identifier? What’s that?
The custom XML part has a properties partImplicit relationship in customXmlPart.xml.relsThe properties part specifies a Custom XML Data Identifier
DEMO
Office Open XML Developer Workshop
Content Control ToolkitContent Control Toolkit
Open-source developer toolhttp://www.codeplex.com/Wiki/View.aspx?ProjectName=dbe
Automatically generates parts, relationships, and markup to bind custom XML parts to content controls
Use to create data-bound documents with no programmingUse as a learning tool, to generate markup for use in custom solutions
DEMO
Office Open XML Developer Workshop
CUSTOM XML MARKUPCUSTOM XML MARKUP
Office Open XML Developer Workshop
Custom XML Markup BasicsCustom XML Markup Basics
Allows embedding the structure from any XML schema into a WordprocessingML document
You don’t have to have a schemaYour XML doesn’t have to validate against your schema
Custom XML elements may have custom attributesWhatever is required within your schemaOpen XML consumers/producers preserve your attributes
Office Open XML Developer Workshop
Where can Custom Xml Markup appear?Where can Custom Xml Markup appear?
Custom XML markup can appear at two levels
Block level (around and/or sibling to paragraphs)Inline (around and/or sibling to runs)
Custom XML markup may be nestedComplex multi-level data semantics may be used
Office Open XML Developer Workshop
Custom XML Markup ExampleCustom XML Markup Example
DEMO
Office Open XML Developer Workshop
Custom XML Markup: Why <customXml>?Custom XML Markup: Why <customXml>?
Why not just embed the custom XML directly in the WordprocessingML document?
Answer: this way, your custom schema doesn’t need to support WordprocessingML within it
This abstraction provides the flexibility to support any schema in custom XML markup
Office Open XML Developer Workshop
CUSTOM XML MAPPINGCUSTOM XML MAPPING
Office Open XML Developer Workshop
XML Mapping OverviewXML Mapping Overview
Your custom schema / XML added to a workbook
XML elements & attributes ‘mapped’ to cells & Tables
Store a copy of the schema in the workbook
Top level map object
Custom properties on each cell or column
Office Open XML Developer Workshop
ExampleExample
Office Open XML Developer Workshop
How It All Ties TogetherHow It All Ties Together
Map Object
Table1
Schema
Cell 1
Table 2 Cell 2
SchemaId
mapId
mapIdmapId
mapId
Office Open XML Developer Workshop
Custom XML SourceCustom XML Source
A cache of the user schemas added to the workbook (xmlmaps.xml)Nodes mapped to tables (table1.xml)Nodes mapped to single cells (tableSingleCells1.xml)
Office Open XML Developer Workshop
xmlMaps.xmlxmlMaps.xml
………
…
Office Open XML Developer Workshop
Table1.xmlTable1.xml
Office Open XML Developer Workshop
tableSingleCells.xmltableSingleCells.xml
Office Open XML Developer Workshop
Custom XML Mapping ExampleCustom XML Mapping Example
Save this XML to a file on your desktop:
<?xml version="1.0"?>
<p:PhoneBook xmlns:p="urn:somePhoneBook">
<p:Entry>
<p:FirstName>Brian</p:FirstName>
<p:LastName>Jones</p:LastName>
<p:Number>(425) 123-4567</p:Number>
</p:Entry>
<p:Entry>
<p:FirstName>Chad</p:FirstName>
<p:LastName>Rothschiller</p:LastName>
<p:Number>(425) 123-4567</p:Number>
</p:Entry>
</p:PhoneBook>
Office Open XML Developer Workshop
Custom XML Mapping ExampleCustom XML Mapping Example
Map the Schema– Open a blank Excel spreadsheet. – On the Data ribbon choose From Other Sources / From
XML Data Import. – Find the XML file you just saved and double-click it.
Import your Data– Following the prompts to map to the SML schema and
import the data to the worksheet.
Export the ResultsRight-click the list under the XML flyout and choose Export…
Office Open XML Developer Workshop
SMART TAGSSMART TAGS
Office Open XML Developer Workshop
Smart TagsSmart Tags
Semantics may be added to a run or set of runsProvides information about the type of information
• May have application-specific implementation (e.g., purple underline)• Semantics are application-independent
Office Open XML Developer Workshop
Smart Tag Property BagSmart Tag Property Bag
You may want to store additional properties for your smart-tag element
These can be added to <smartTagPr>Any number of custom namespace/element/value settings
Once embedded, consumers can ignore the semantics without affecting the presentation of the documentProducers must preserve the semantic informationOptionally, a producer may use smart tag data to provide context-sensitive functionality
Office Open XML Developer Workshop
Converting Office 2003 smart-tag syntaxConverting Office 2003 smart-tag syntaxIn Office 2003, smart tags used this syntax:<wordDocument>
<body>
<p>
<r><t>Name:</t></r>
<ns0:FirstName><r><t>Brian</r></t></ns0:FirstName>
</p>
</body>
</wordDocument>
In Office Open XML, it works like this:<document> <body> <p> <r><t>Name:</t></r> <customXml uri=“mySchema” element="ns0:FirstName"> <r><t>Brian</r></t> </customXml> </p> </body></document>
Office Open XML Developer Workshop