Код:
[Code]
/////////////////////////////////////////////////
procedure VehiclesConfig(const FileName: string);
var
XMLDoc, XMLNodes, XMLNode: Variant;
XPath: string;
begin
try
XMLDoc := CreateOleObject('Msxml2.DOMDocument');
XMLDoc.setProperty('SelectionLanguage', 'XPath');
XMLDoc.async := False;
XMLDoc.load(FileName);
if XMLDoc.parseError.errorCode <> 0 then
RaiseException(string(XMLDoc.parseError.reason));
XMLNode := XMLDoc.createElement('MediaPath');
XMLNode.setAttribute('Path', 'Vehicles');
XPath := '/Config/MediaPath[@Path="Media" and not(following-sibling::*[1][self::MediaPath[@Path="Vehicles"]])]/following-sibling::*[1]';
#if (Ver < 0x5050600) ; avoid VarIsNull
XMLNodes := XMLDoc.selectNodes(XPath);
if XMLNodes.length = 1 then
XMLDoc.documentElement.insertBefore(XMLNode, XMLNodes.item(0));
#else
XMLNodes := XMLDoc.selectSingleNode(XPath);
if not VarIsClear(XMLNodes) then
XMLDoc.documentElement.insertBefore(XMLNode, XMLNodes);
#endif
XMLDoc.save(FileName);
except
ShowExceptionMessage;
finally
end;
end;
///////////////////////////
procedure InitializeWizard;
begin
VehiclesConfig('{#SourcePath}\example.xml');
end;