I'm not familiar with pascal and I tried asking this in multiple sites already and haven't really gotten a useful answer besides telling me to use MSXML.
I have an XML file structured something like this
I want the installer to look for a Book named Bob's Book (static value) then edit the author from Bob to a custom input that a user enters in the installer.
This is the code I have so far, I was thinking of getting the children of the Library node then checking whether it's has a child node called Name which has the value "Bob's Book" and if yes, look for that book's child node author and edit it. But I can't find out whether the type returned for getElementsByTagName() is an array or something else and whether there are compare methods for xml nodes.. There doesn't seem to be an API out there for Pascal either.
I have an XML file structured something like this
Code:
<Library>
<Book>
<Name>Bobs Book</Name>
<Author> Bob </Author>
</Book>
<Book>
<Name> George's Book</Name>
<Author> George's Book</Author>
</Book>
</Library>
I want the installer to look for a Book named Bob's Book (static value) then edit the author from Bob to a custom input that a user enters in the installer.
This is the code I have so far, I was thinking of getting the children of the Library node then checking whether it's has a child node called Name which has the value "Bob's Book" and if yes, look for that book's child node author and edit it. But I can't find out whether the type returned for getElementsByTagName() is an array or something else and whether there are compare methods for xml nodes.. There doesn't seem to be an API out there for Pascal either.
Code:
{--- Custom input wizard pages ---}
procedure InitializeWizard;
var
HostPage: TInputQueryWizardPage;
begin
{ Create the pages }
HostPage := CreateInputQueryPage(wpWelcome,
'Book Information', 'Book Info',
'Please specify the information');
HostPage.Add('Hostname:', False);
end;
{--- MSXML ---}
const
XMLFile = 'test.xml';
procedure parseXML;
var
objNodeList, XMLDoc, RootNode: Variant;
Path: String;
i: Integer;
begin
Path := ExpandConstant('{app}\server\standard\deploy\');
XMLDoc := CreateOleObject('MSXML2.DOMDocument');
XMLDoc.async := False;
XMLDoc.resolveExternals := False;
XMLDoc.load(Path + XMLFile);
if XMLDoc.parseError.errorCode <> 0 then
RaiseException('Error on line ' + IntToStr(XMLDoc.parseError.line) + ', position ' + IntToStr(XMLDoc.parseError.linepos) + ': ' + XMLDoc.parseError.reason);
objNodeList = XMLDoc.getElementsByTagName("Library");
for i := 0 to Length(objNodeList)-1 do
if objNodeList[i].getAttributeNode('Book').XML = 'Bobs Book' then
objNodeList[i].setAttribute('author', 'test');
end;
Function GetHostname(Param: TInputQueryWizardPage): string;
begin
Result := Param.Values[0];
end;
Last edited: