[Expand all]   [Collapse all]

Introduction

XiMoL allows to read XML file with the XML structure.

Open a File

Open/Close sectionXiMoL_ReadXmlFile

Open a XML file, read the data, and return a handler to the data structure. All data are in memory at this time.

Parameters:

  1. HANDLER : (Output) An abstract pointer to fetch the data in memory.
  2. FILENAME : (Input) The filename.

Usage:

!insertmacro XiMoL_ReadXmlFile HANDLER FILENAME

Example:

!insertmacro XiMoL_ReadXmlFile $XMLHandler "test1.xml"

XML Element

Open/Close sectionXiMoL_GetTag

Get the tag of the element pointed by the handler.

Parameters:

  1. HANDLER : (Inupt) An abstract pointer to fetch the data in memory.
  2. TAG : (Ouput) The tag.

Usage:

!insertmacro XiMoL_GetTag HANDLER TAG

Example:

!insertmacro XiMoL_GetTag $XMLHandler $0

Open/Close sectionXiMoL_GetContent

Get the content of the element pointed by the handler.

Parameters:

  1. HANDLER : (Inupt) An abstract pointer to fetch the data in memory.
  2. CONTENT : (Ouput) The content.

Usage:

!insertmacro XiMoL_GetTag HANDLER CONTENT

Example:

!insertmacro XiMoL_GetContent $XMLHandler $0

XML Attributes

Open/Close sectionXiMoL_GetNumberOfAttributes

Return the number of attribute of the element pointed by the handler.

Parameters:

  1. HANDLER : (Input) An abstract pointer to fetch the data in memory.
  2. NB : (Ouput) The number of attribute of the data.

Usage:

!insertmacro XiMoL_GetNumberOfAttributes HANDLER NB

Example:

!insertmacro XiMoL_GetNumberOfAttributes $XMLHandler $0

Open/Close section XiMoL_GetAttributeName

Return the name of attribute number nb of the element pointed by the handler.

Parameters:

  1. HANDLER : (Input) An abstract pointer to fetch the data in memory.
  2. NB : (Input) The number of attribute of the data.
  3. NAME : (Ouput) The name of the attribute number NB of the data.

Usage:

!insertmacro XiMoL_GetAttributeName HANDLER NB NAME

Example:

!insertmacro XiMoL_GetAttributeName $XMLHandler 0 $0

Open/Close section XiMoL_GetAttributeValue

Return the value of the attribute named ATTRIBUTE_NAME of the element pointed by the handler. If the attribute name does not exist then an empty string is return.

Parameters:

  1. HANDLER : (Input) An abstract pointer to fetch the data in memory.
  2. ATTRIBUTE_NAME : (Input) The name of the attribute.
  3. VALUE : (Ouput) The value of the attribute. The value is empty if the attribute does not exist.

Usage:

!insertmacro XiMoL_GetAttributeValue HANDLER ATTRIBUTE_NAME VALUE

Example:

!insertmacro XiMoL_GetAttributeValue $XMLHandler "size" $0

DOM Navigation

Open/Close section XiMoL_GetNumberOfElements

Get the number of elements of the data pointed by the handler.

Parameters:

  1. HANDLER : (Input) An abstract pointer to fetch the data in memory.
  2. NB : (Output) Number of element.

Usage:

!insertmacro XiMoL_GetNumberOfElements HANDLER NB

Example:

!insertmacro XiMoL_GetNumberOfElements $XMLHandler $0

Open/Close section XiMoL_GetElementName

Get the name of the element nb of the data pointed by the handler.

Parameters:

  1. HANDLER : (Input) An abstract pointer to fetch the data in memory.
  2. NB : (Input) Number of the element.
  3. NAME : (Ouput) Name of the element. An empty string is return if the element does not exist

Usage:

!insertmacro XiMoL_GetElementName HANDLER NB NAME

Example:

!insertmacro XiMoL_GetElementName $XMLHandler 1 $0

Open/Close section XiMoL_GetElement

Get a new handler to a sub element.

Parameters:

  1. HANDLER : (Input) An abstract pointer to fetch the data in memory.
  2. NB : (Input) Number of the element.
  3. NEW_HANDLER : (Ouput) a new handler pointed to the element number NB. If the element does not exist, the handler is not valide and an error will occur at the next call of XiMoL

Usage:

!insertmacro XiMoL_GetElement HANDLER NB NEW_HANDLER

Example:

!insertmacro XiMoL_GetElement $XMLHandler 1 $XMLHandler2

Open/Close section XiMoL_GetNextElement

Move the element pointed by the handler to the next element and got to the label GOTO_IF_SUCCES if the element exist.

Parameters:

  1. HANDLER : (Input) An abstract pointer to fetch the data in memory.
  2. GOTO_IF_SUCCES : (Input) Label to goto if the next element exist.

Usage:

!insertmacro XiMoL_GetNextElement HANDLER GOTO_IF_SUCCES

Example:

#
# print all sub element tag
#
; Open the file
!insertmacro XiMoL_ReadXmlFile $XMLHandlerRoot "test.xml"
; Get the number of elements
!insertmacro XiMoL_GetNumberOfElements $XMLHandlerRoot $0
; if the number is 0 go to end
StrCmp $0 "0" PrintElementTagEnd
; Get the first element
!insertmacro XiMoL_GetElement $XMLHandlerRoot 0 $XMLHandler
PrintElementTag:
; Get the tag
!insertmacro XiMoL_GetTag $XMLHandler $0
MessageBox MB_OK "tag=$0"
; Goto the next element
!insertmacro XiMoL_GetNextElement $XMLHandler PrintElementTag
PrintElementTagEnd:
              

Open/Close section XiMoL_GetElementFromPath

Get a new handler define by a path. An error occur when the element does not exist.

Parameters:

  1. HANDLER : (Input) An abstract pointer to fetch the data in memory.
  2. PATH : (Input) A path to the new element. The path "" define the first sub element of the data. The path "Tag/" will point to the first sub element named "Tag". You could have a long path like "Tag1/Tag2/Tag3/" and then the New handler will have the tag "Tag3". The path must be finish by a "/".
  3. NEW_HANDLER : (Ouput) A handler to the new element.

Usage:

!insertmacro XiMoL_GetElementFromPath HANDLER PATH NEW_HANDLER

Example:

!insertmacro XiMoL_GetElementFromPath $XMLHandler "Data/x/" $handlerToX

Open/Close section XiMoL_IfPathExists

test a Path and goto the label.

Parameters:

  1. HANDLER : (Input) An abstract pointer to fetch the data in memory.
  2. PATH : (Input) A path to the new element. See XiMoL_GetElementFromPath.
  3. GOTO_IF_PATH_EXISTS : (Input) Label to goto if path exist.
  4. GOTO_IF_NOT : (Input) Label to goto if path does not exist.

Usage:

!insertmacro XiMoL_IfPathExists HANDLER PATH GOTO_IF_PATH_EXISTS GOTO_IF_NOT

Example:

!insertmacro XiMoL_IfPathExists $XMLHandler "Data/x/" have_x does_not_have_x

Error handling

Open/Close section XiMoL_GetErrorMessage

return the last error message.

Parameters:

  1. VAR : (Output) A variable to store the message.

Usage:

!insertmacro XiMoL_GetErrorMessage VAR

Example:

!insertmacro XiMoL_GetErrorMessage $0

Open/Close section XiMoL_GetLastCall

return the last call to XiMoL.

Parameters:

  1. VAR : (Output) A variable to store the instruction.

Usage:

!insertmacro XiMoL_GetLastCall VAR

Example:

!insertmacro XiMoL_GetLastCall $0

Open/Close section XiMoL_SetErrorGotoLabel

Define the label to goto if an error occur during a XiMoL Call.

Parameters:

  1. LABEL : (Input) Define the error handling label. During the next XiMoL Call if an error occur, the execution flow will go to the LABEL

Usage:

!insertmacro XiMoL_SetErrorGotoLabel LABEL

Example:

!insertmacro XiMoL_SetErrorGotoLabel xml_error_handler

Open/Close section XiMoL_ResetErrorGotoLabel

Reset the error goto Label.

Parameters:

Usage:

!insertmacro XiMoL_ResetErrorGotoLabel

Example:

!insertmacro XiMoL_ResetErrorGotoLabel

Source code

NSIS plug-in (C++)

The source of the NSIS plug-in can be found in the XiMoL project at sourceforge.net. SourceForge.net Logo If you have any questions about XiMoL, you could write to tournois@users.sourceforge.net.

Version history

  • 1.0 beta 1
    • First Version.

Credits

Written by Florent Tournois

License GPL

#=============================================================================#
#                                                                             #
#    "XiMoL NSIS contrib"                                                     #
#    Copyright (C) 2005 Florent Tournois                                      #
#                                                                             #
# This program is free software; you can redistribute it and/or               #
# modify it under the terms of the GNU General Public License                 #
# as published by the Free Software Foundation; either version 2              #
# of the License, or (at your option) any later version.                      #
#                                                                             #
# This program is distributed in the hope that it will be useful,             #
# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
# GNU General Public License for more details.                                #
#                                                                             #
# You should have received a copy of the GNU General Public License           #
# along with this program; if not, write to the Free Software                 #
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,                  #
# MA  02110-1301, USA.                                                        #
#                                                                             #
#=============================================================================#