-
-
Save rwilkes/bce896c5a013de464bdfef7c576b6a66 to your computer and use it in GitHub Desktop.
Xml tools for InnoSetup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Code] | |
function LoadValueFromXML(const AFileName, APath: string): string; | |
var | |
XMLNode: Variant; | |
XMLDocument: Variant; | |
begin | |
Log('Get Xml text node: ' + AFileName); | |
Result := ''; | |
XMLDocument := CreateOleObject('Msxml2.DOMDocument.6.0'); | |
try | |
XMLDocument.async := False; | |
XMLDocument.load(AFileName); | |
if (XMLDocument.parseError.errorCode <> 0) then | |
MsgBox('The XML file could not be parsed. ' + XMLDocument.parseError.reason, mbError, MB_OK) | |
else begin | |
XMLDocument.setProperty('SelectionLanguage', 'XPath'); | |
XMLNode := XMLDocument.selectSingleNode(APath); | |
Result := XMLNode.text; | |
end; | |
except | |
MsgBox('An error occured!' + #13#10 + GetExceptionMessage, mbError, MB_OK); | |
end; | |
end; | |
procedure SaveValueToXML(const AFileName, APath, AValue: string); | |
var | |
XMLNode: Variant; | |
XMLDocument: Variant; | |
begin | |
Log('Save Xml text node: ' + AFileName); | |
XMLDocument := CreateOleObject('Msxml2.DOMDocument.6.0'); | |
try | |
XMLDocument.async := False; | |
XMLDocument.load(AFileName); | |
if (XMLDocument.parseError.errorCode <> 0) then | |
MsgBox('The XML file could not be parsed. ' + XMLDocument.parseError.reason, mbError, MB_OK) | |
else begin | |
XMLDocument.setProperty('SelectionLanguage', 'XPath'); | |
XMLNode := XMLDocument.selectSingleNode(APath); | |
XMLNode.text := AValue; | |
XMLDocument.save(AFileName); | |
end; | |
except | |
MsgBox('An error occured!' + #13#10 + GetExceptionMessage, mbError, MB_OK); | |
end; | |
end; | |
procedure SaveAttributeValueToXML(const AFileName, APath, AAttribute, AValue: string); | |
var | |
XMLNode: Variant; | |
XMLDocument: Variant; | |
begin | |
Log('Save Xml attr: ' + AFileName); | |
XMLDocument := CreateOleObject('Msxml2.DOMDocument.6.0'); | |
try | |
XMLDocument.async := False; | |
XMLDocument.load(AFileName); | |
if (XMLDocument.parseError.errorCode <> 0) then | |
MsgBox('The XML file could not be parsed. ' + XMLDocument.parseError.reason, mbError, MB_OK) | |
else begin | |
XMLDocument.setProperty('SelectionLanguage', 'XPath'); | |
XMLNode := XMLDocument.selectSingleNode(APath); | |
XMLNode.setAttribute(AAttribute, AValue); | |
XMLDocument.save(AFileName); | |
end; | |
except | |
MsgBox('An error occured!' + #13#10 + GetExceptionMessage, mbError, MB_OK); | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment