Tip Comments in XML Documents

To make your XML documents legible comment, you can use any characters, and clear, you should use comments. except for a double-hyphen (--). A the XML processor ignores all comment can be placed anywhere commented text. A comment begins within an XML document provided that with the <! -- characters and ends with it's outside (not within) other markup the -- > characters. Within your tags.

Sfi UquiscsDotals_him Notepad

Fie Edh Formal Häp

<!•' BEGINNING Of XML Data Island -> OWL ID-W*TilDaa*>

<TTtfe>Besinriiiifl VBAin Bteel<nnie> <Eland3t«>I/3/2£l03</itartdsti > <Sess«rk5>e</Sts5ion5> </Cwjrse>

<rtle>lntenre«3ate V/SAri &»eli/rtle> <sian<laieHA3/2003</sia'idse>

<Ilto>fld«arcs<3 WAr ShmI</Wb> <5lar!d3tei^0/20lj3</sta1datt >

<3sssioris>12V3essiww>

<!•• BEGINNING OF HTVLFORMATTING INSTRUCTIONS ->

<H2>Lisi of Courses VH2>

<TH?iB>Course HVB><nH> <rN><e>mtn <jb><ith> <TH><B>Start Dai« </B>4TH> <TH"B>Sessions </B> <I7H£AD > <TR>

<TO?<OIV DATAF LD="IO"<f DIV> </TO > croxoiu WftAf Ld="THi4">i/cnw><rrD> <TO><DIV DAW LD"'SlartDate"> <)DN> <rtO> <T0?iDIV D»T*F LD-'Ses3ions*> VDIVAtfTDi

<!- END OF HTML FORMATTING ISTRUCTIONS ->

Figure 17-20:

This file shows how to bind HTML tags to data fields in an XML data island. The result of this code is shown in Figure 17-21.

<!- END OF HTML FORMATTING ISTRUCTIONS ->

Figure 17-21:

This table was generated by binding HTML tags to data fields in an XML data island (see Figure 17-20).

Figure 17-21:

This table was generated by binding HTML tags to data fields in an XML data island (see Figure 17-20).

Data islands can also be used to refer to an external XML document by specifying the src attribute in association with the xml element. This way instead of embedding the XML data within an HTML document, you can create a reference to the existing XML document, as shown in the code below.

The following exercise demonstrates how to create XML data islands in an HTML document.

1. Open Notepad and enter the code shown below.

2. Save this code as CoursesDataIs2.htm.

3. Open the file in your browser. The result should match Figure 17-21.

<! -- BEGINNING OF XML Data Island --> <XML ID="MyXmlData" src="Courses.xml"> </XML>

<! -- BEGINNING OF HTML FORMATTING INSTRUCTIONS --> <H2>List of Courses</H2> <TABLE datasrc=#MyXmlData border=1> <THEAD>

<TH><B>Course Id</B></TH> <TH><B>Title</B></TH> <TH><B>Start Date</B></TH> <TH><B>Sessions</B></TH> </THEAD> <TR>

<TD><DIV DATAFLD="ID"</DIV></TD> <TD><DIV DATAFLD="Title"></DIV></TD> <TD><DIV DATAFLD="StartDate"></DIV></TD> <TD><DIV DATAFLD="Sessions"></DIV></TD>

<! -- END OF HTML FORMATTING ISTRUCTIONS -- >

The code above demonstrates how to create an XML data island that references an external XML document.

0 0

Post a comment