Eksempel
Dette XML dokument bliver data læst fra:
<?xml version="1.0" encoding="utf-8"?>
<SQLAdmin>
<fileinfo>
<author>Niels Grove-Rasmussen</author>
</fileinfo>
<SQLinstance>
<winsrvname>Siegfried.prod.sqldba.dk</winsrvname>
<IP4>192.168.001.042</IP4>
<windescr>First internal SQL Server server</windescr>
<sqlinstancename>Stometoc</sqlinstancename>
<TCP>4200</TCP>
<sqldescr>First internal SQL Server instance</sqldescr>
<share>
<sharename>D$</sharename>
<sharedesc>D-drev</sharedesc>
</share>
<share>
<sharename>E$</sharename>
<sharedesc>E-drev</sharedesc>
</share>
<share>
<sharename>F$</sharename>
<sharedesc>F-drev</sharedesc>
</share>
</SQLinstance>
<SQLinstance>
<winsrvname>Sandbox.SQLAdmin.dk</winsrvname>
<IP4></IP4>
<windescr>Sandbox server</windescr>
<sqlinstancename>SQL000</sqlinstancename>
<TCP></TCP>
<sqldescr>Primary sandbox SQL Server instance</sqldescr>
<share>
<sharename>C$</sharename>
<sharedesc>C-drev</sharedesc>
</share>
</SQLinstance>
</SQLAdmin>
Dette er scriptet (JScript), som læser data ved hjælp af DOM og MSXML:
SQLAdminXML = "SQLAdmin.xml"; // XML document with metadata
var objXML = new ActiveXObject( "MSXML2.DOMDocument.6.0" );
objXML.async = false;
try {
objXML.load( SQLAdminXML );
}
catch( e ) {
alert( 'ERROR: Could not load the config file "' + SQLAdminXML + '".' );
objXML = null;
throw( e );
}
var SQLInstances = objXML.getElementsByTagName( "SQLinstance" );
for(var i = 0; i < SQLInstances.length; i++ ) {
WScript.Echo( "Windows Server name = " + SQLInstances[i].getElementsByTagName( "winsrvname" )[0].text );
var Shares = SQLInstances[i].getElementsByTagName( "share" );
for( var j = 0; j < Shares.length; j++ ) {
WScript.Echo( "Share '" + Shares[j].getElementsByTagName( "sharename" )[0].text + "': " + Shares[j].getElementsByTagName( "sharedesc" )[0].text );
}
Shares = null;
}
SQLInstances = null;
objXML = null;