Mapping XML Elements to Your Document

To base a document on XML, you must attach an XML schema to your document and begin mapping the XML elements.

1. Attach the XML schema to your document by selecting Templates and Add-Ins from the Microsoft Office Word Tools menu.

2. Click Add Schema on the Schema tab, and select the schema you just created in Listing 5.13.

3. Type any text into the Alias field of the Schema Settings dialog box, and click OK.

You map each element by selecting the desired text in the document and then clicking the element in the XML Structure task pane.

4. Map the Letter node to the entire document.

5. Select the area starting at the company address until right before the Re line, and map the Address node.

6. Select the area of the salutation to the end of the letter, and map the Content node.

7. Map the child nodes of the Address node (Author and Addressee) and child nodes of the Content node (Salutation, Body, and Closing) to appropriate areas within the document.

Your final document should resemble the one in Figure 5.11.

Fie Ldt Vttm Prcject Ojtd Debug Data Tods Intert Format lable Wrrfow Ufmmunty lleJp

J 4 Ji ¿a - y 0 . 1 a - ■ • * y :

/o^,^^Docurr^entl.dl>t, Oblcct Erowsef

tjLT-ull -T..'j!

> 1

I 2Î H ^ i3|| y , ftfc (ft 1 "O - f » imn> - £ : Norntt - (mes Hew Komai g J,., -B

- B / ït f= jg

Q1 J> 211 m iw^n^nr,

H WUUDvurnAL.ilK <J ïtiWjmiwrt-\ti

:

Uenwnts ri the document

dï HirPitijeul

1

MeGrath & Stnbbs Consulting Services

C«*ervKw Avenue ) Seattle, WA 98005 425-555>5555

R iaUei

E-crtent 1 vir.vww uody CbUng

^AiniFxi*«. [jJJWUSOvM*

i* "lftdiaîî«,■ I

LeUerMifre&&Muili! Miiinolt.iHI j.s,Tu -

Re: Î1ÛTTÏÎM*««']

3

CD ii'iitaUfHWvjs) *

(name} LetterAddr«ina<

(* CcfterttPey lSduUtionO )

lit ^Jmw 'M tngi In tfw- itwimrat

Ohium) an ifaismii lu aivty to yum , t ancntftlKbc'i:

1 |lftvH ivrttMNvfcliivrf'.ul

M-ritM'. FHriul

NoiiBSfWtoURl littu'.WnivT,,ih.._

JCertrmi») lienor») jJ

Rtvif

iNwfeT'rtw

*

Cluwiii

i™ H

Il tb-é.f, Uw riaiw uuxJ ii lude lu Un My tte nhlnrt.

111 List art/ cMd elements ci curent clement

^atfljJ |

Rn

*ty

Â

Figure 5.11. Mapping XML to a document

Figure 5.11. Mapping XML to a document

Each time you map an element from the XML Structure task pane to the document, a new XMLNode control is added to the Controls collection. You will learn more about XMLNode controls in Chapter 6. For this example, all you need to know is that these XMLNodes have events that you can program against.

The name of each XMLNode control contains the parent schema element name, followed by the schema element name, followed by the word Node. For example, the Address node is named LetterAddressNode.

0 0

Post a comment