Scrigroup - Documente si articole

Username / Parola inexistente      

Home Documente Upload Resurse Alte limbi doc  

AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows

AspAutocadCDot netExcelFox proHtmlJava
LinuxMathcadPhotoshopPhpSqlVisual studioWindowsXml

Importing the Data from Multiple XML Files


+ Font mai mare | - Font mai mic


Trimite pe Messenger
Accessing Oracle XML DB Repository Data
Importing the Data from Multiple XML Files

Importing the Data from Multiple XML Files

It's a simple matter to import more than one file with the same structure into an HTML file. Basically, you just need to repeat the operation, making sure that the uniqueness of target tag names and variables is preserved.

Listing 2.5 contains an XML file whose structure matches that of the ones used so far. The values of the data components have been changed so that they can be differentiated from the others when read by the HTML files.

Example 2.5. The Second File for the Reading of Two XML Files
1: <?xml version='1.0' ?>
5: <CC>Editor</CC>
6: <SUBJECT>Your introduction to XML</SUBJECT>
7: <BODY>I am with you so far.</BODY>
8: <POSTSCRIPT>I am enjoying it so far.</POSTSCRIPT>

Note that this data has the same structure as that of the other XML files; the differences are in the data values.

The next step is to create a program that will read in the data of both XML files. It will be necessary to create two instances of the xmldom object, one for each file. You'll also create another set of <span> tags in the HTML section to serve as the targets of the extracted data.

Listing 2.6 is a modification of the previous one. It has been altered to read the data from two XML files having the same form. All changes from the previous one are marked in bold.

Example 2.6. Reading Two XML Files That Have the Same Form
5: var RootElement1;
6: var RootElement2;
7: var xmlDoc1=new ActiveXObject('microsoft.xmldom');
8: xmlDoc1.load('listing2-3.xml');
9: var xmlDoc2=new ActiveXObject('microsoft.xmldom');
10: xmlDoc2.load('listing2-5.xml');
11:function StartUp()


function StartLoading()

<BODY onLoad='StartUp()'>
44:TO:&nbsp;<SPAN ID=todata1></SPAN><BR>
45:FROM:&nbsp;<SPAN ID=fromdata1></SPAN><BR>
46:CC:&nbsp;<SPAN ID=ccdata1></SPAN><BR>
47:SUBJECT:&nbsp;<SPAN ID=subjectdata1></SPAN><BR>
48:BODY:&nbsp;<SPAN ID=bodydata1></SPAN><BR>
49:POSTSCRIPT:&nbsp;<SPAN ID=psdata1></SPAN><BR>
53:TO:&nbsp;<SPAN ID=todata2></SPAN><BR>
54:FROM:&nbsp;<SPAN ID=fromdata2></SPAN><BR>
55:CC:&nbsp;<SPAN ID=ccdata2></SPAN><BR>
56:SUBJECT:&nbsp;<SPAN ID=subjectdata2></SPAN><BR>
57:BODY:&nbsp;<SPAN ID=bodydata2></SPAN><BR>
58:POSTSCRIPT:&nbsp;<SPAN ID=psdata2></SPAN><BR>

When you run the file, note that the output that appears in the document window is the data from the two message files. This output is illustrated in Figure 2.4.

Line 6 declares the second instance of the xmldom object needed for the second XML file. Lines 9 and 10 create the object and the file's attachment.

Figure 2.4. The output of reading and displaying two files.

graphics/02fig0height=397.97333333333 .gif

In lines 33 to 38, the second xmldom object is used to extract the data from the file and insert it into the second set of <span> tags.

Lines 50 to 52 create a separation between the two sets of <span> tags, and lines 53 to 58 define the second target set of tags.

Delivered for Juan Ignacio Velazquez Gonzalez
Swap Option Available: 3/30/2002

Last updated on 9/12/2001
Sams Teach Yourself XML in 24 Hours,  2002 Sams Publishing

Politica de confidentialitate



Vizualizari: 1135
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2022 . All rights reserved

Distribuie URL

Adauga cod HTML in site