var
node: IXMLDOMNode;
nodes: IXMLDOMNodeList;
sOle: OleVariant;
s: String;
// Parsen des
XML-Dokumentes
begin
xmlDoc := CoDOMDocument30.Create;
//xmlDoc.setProperty('NewParser', true); --> nur für 4.0 Version!
xmlDoc.validateOnParse := False;
xmlDoc.resolveExternals := False;
xmlDoc.async := False;
xmlDoc.preserveWhiteSpace := False;
if not xmlDoc.load(sDateiname) then
MessageDlg('
XML-Datei nicht vorhanden!', mtWarning, [mbOK], 0);
// Durchlaufen einer NodeList: -----------------------------------------------
nodes := xmlDoc.selectNodes('//recorddata[0]/*');
node := xmlDoc.selectSingleNode('//recorddata[0]/*');
for i := 0 to nodes.length-1 do
begin
if (node <> nil) then
begin
node := nodes.nextNode;
// einlesen des nodeValues, dabei ist das Ergebnis vom Typ OleVariant
sOle := node.Get_nodeValue;
case varType(sOle) of
varStrArg: ShowMessage('
COM-compatible string');
varEmpty : ShowMessage('The variant is Unassigned');
varOleStr : ShowMessage('Reference to a dynamically allo...');
varVariant : ShowMessage('A variant');
varString : ShowMessage('Reference to a dynamically ...');
varNull : ShowMessage('The variant is Null.');
varSmallint : ShowMessage('16-bit signed integer (type Sm....');
varInteger : ShowMessage('32-bit signed integer (type Integ...).');
varSingle : ShowMessage('Single-precision floating-point valu....');
varDouble : ShowMessage('Double-precision floating-point value (type double).');
varCurrency : ShowMessage('Currency floating-point value (type Currency).');
varDate : ShowMessage('Date and time value (type TDateTime).');
varDispatch : ShowMessage('Reference to an Automation object (an IDi....');
varError : ShowMessage('Operating system error code.');
varBoolean : ShowMessage('16-bit boolean (type WordBool).');
varUnknown : ShowMessage('Reference to an unknown object (an IInterface or IUnknown interface pointer).');
varByte : ShowMessage('A Byte');
varAny : ShowMessage('A CORBA Any value.');
end;
{
// wir wollen jetzt das Ergebnis vom Typ OleVariant
// in einen String umwandeln
iResult := VariantChangeType( sOle,
sOle,
0,
VT_BSTR);
// das Ergebnis der Umwandlung prüfen
case iResult of
S_OK: ShowMessage('Success.');
DISP_E_BADVARTYPE: ShowMessage('The variant type vtNew ....');
DISP_E_OVERFLOW:ShowMessage('The data pointed to by p.....');
DISP_E_TYPEMISMATCH: ShowMessage('The argument could not ....');
E_INVALIDARG: ShowMessage('One of the arguments is invalid.');
E_OUTOFMEMORY: ShowMessage('Memory could not be allocated for the conversion.');
end;
// wenn Ergebnis ok ist weiterverfahren ansonsten abbrechen
if iResult <> S_OK then
exit;
}
s := '';
//s := VarAsType(sOle, varString);
// If VariantChangeType did not return an error,
// the argument could then be fetched directly from the bstrVal field of the VARIANTARG
//s:= sOle.bstrval;
MessageDlg( 'lfd. Nr.: ' + #9 + IntToStr(i) + #13#10 +
'Nodename: ' + #9 + node.Get_nodeName + #13#10 +
'NodeInhalt: ' + #9 + node.xml + #13#10 +
'Get_NodeValue: ' + #9 + s + #13#10 +
'NodeGetText: ' + #9 + node.Get_text,
mtInformation, [mbOK], 0);
end;
end;