Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Code]
- function TryGetAttrValuesByIndices(const FileName, Path, Attribute: string;
- const Indices: TArrayOfInteger; out Values: TArrayOfString): Boolean;
- var
- I: Integer;
- XMLDocument: Variant;
- XMLNodeList: Variant;
- begin
- Result := False;
- XMLDocument := CreateOleObject('Msxml2.DOMDocument');
- try
- XMLDocument.async := False;
- XMLDocument.load(FileName);
- if (XMLDocument.parseError.errorCode <> 0) then
- RaiseException(XMLDocument.parseError.reason)
- else
- begin
- XMLDocument.setProperty('SelectionLanguage', 'XPath');
- XMLNodeList := XMLDocument.selectNodes(Path);
- SetArrayLength(Values, GetArrayLength(Indices));
- for I := 0 to GetArrayLength(Indices) - 1 do
- Values[I] := XMLNodeList.item(Indices[I]).getAttribute(Attribute);
- Result := True;
- end;
- except
- MsgBox('An error occured!' + #13#10 + GetExceptionMessage, mbError, MB_OK);
- end;
- end;
- procedure InitializeWizard;
- var
- StrArray: TArrayOfString;
- IntArray: TArrayOfInteger;
- begin
- SetArrayLength(IntArray, 2);
- IntArray[0] := 1;
- IntArray[1] := 2;
- if TryGetAttrValuesByIndices('C:\File.xml',
- '//context/object/*', 'value', IntArray, StrArray) then
- begin
- MsgBox(Format(
- 'Item 1: %s' + #13#10 + 'Item 2: %s', [
- StrArray[0], StrArray[1]]
- ), mbInformation, MB_OK);
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement