help with pascal script in inno setup

syn3rgyz

Gawd
Joined
Jun 14, 2005
Messages
763
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
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:
Hey syn3rgyz,

Just wanted to say THANK YOU SOOO MUCH for posting this. This + w3schools were the only places I could find some kind of example of how to do this.

If you are still trying to figure out what is returned by getElementsByTagName(), per the w3schools page for that function it returns a NodeList, from which you can call .item(int index) to get an Element. Once you have this, you can use .textContent to get the text between the > < or getAttribute(String name) to get the attributes within the element tag.

For example, if you have the Book element, you can call .getElementsByTagName('Name').items(0).textContent to return the name of the book, e.g. Bobs Book.


Thanks again, hope this helps any future Inno Script XML seekers!
 
Back
Top