Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Open and parse file XML


11 replies to this topic

vince_d

vince_d
  • Members
  • 17 posts

Posted 01 April 2003 - 08:43

I need to open file xml , parse and change some values for distribute my products. We use the kind of files for replacing ini files.

Have you ever do it ?


Regards.

Ozone

Ozone
  • Full Members
  • 77 posts

Posted 01 April 2003 - 19:11

I too work for a company that decided to use XML files instead of INI files for storing information that my installation needed to complete an upgrade. I now rely on an executable that my programming department wrote to read back information that our install needs. I did not need to write information to it.

Here is a sample IS code that I used to read the data section of an XML file. It relies on the fact that the XML file is a text-based file. I seek the name of the field and store the string value in a global list to use elsewhere. In the example below, I am looking for a string “CompanyID=” and the value is 11 characters greater than the starting position of the string “CompanyID=”. Maybe it can help you develop your own code.

// Define this list Globally to read contents in other functions
LIST list_Company_Paths;

////////////////////////////////////////////////////////////////////////
// Function: ReadXML()
//
//////////////////////////////////////////////////////////////////////    
function ReadXML()

STRING svResult , svLine, svSubLine;
NUMBER nResult, nvFileHandle, nStartPosition, nEndPosition, nLastPosition;

begin

//// CompanyID= ////////////////////////////////////////////////

TARGETDIR = "C:\\MyFolder";    
ChangeDirectory ( TARGETDIR );
nResult = FindFile ( TARGETDIR , "MyFile.xml" , svResult );
if nResult = 0 then
       OpenFileMode ( FILE_MODE_NORMAL );
       OpenFile ( nvFileHandle , TARGETDIR , "MyFile.xml" );
       GetLine ( nvFileHandle , svLine );
       CloseFile ( nvFileHandle );

       nLastPosition = StrLength(svLine);

       if nLastPosition > 0 then
               list_Company_Paths = ListCreate ( STRINGLIST );
       endif;

       while nLastPosition > 0
               // read the string svLine
               // MessageBox ( svLine , INFORMATION );
               nStartPosition = StrFind ( svLine , "CompanyID=" );

               if nStartPosition > 0 then // found it
                       nStartPosition = nStartPosition + 11;  // data starts offset
                       StrSub ( svSubLine , svLine , nStartPosition , nLastPosition );
                       nEndPosition = StrFind ( svSubLine , "\"" );
                       StrSub ( svResult , svLine , nStartPosition , nEndPosition );
                      //MessageBox ( svResult , INFORMATION );   //For testing
                      ListAddString ( list_Company_Paths , TARGETDIR ^ svResult , AFTER );
                      svLine = svSubLine;
              else
                      nLastPosition = 0;
              endif;
       endwhile;
endif;

vince_d

vince_d
  • Members
  • 17 posts

Posted 02 April 2003 - 09:55

Thinks
but my file is more complex. i have some big tree and
I can't use some tag.

I think it needs to use MSXML but it wasn't so simple  

Regards

Perotin

Perotin
  • Full Members
  • 407 posts

Posted 03 April 2003 - 14:28

How did you do it?
do you use "UseDll( msxml2.dll )" in the script an prototyp the functions like "selectSingleNode" ...?
Just like using WINAPI functions?
Gruß / regards
Thomas

vince_d

vince_d
  • Members
  • 17 posts

Posted 03 April 2003 - 14:31

Can you give an example ?

Thank you

Perotin

Perotin
  • Full Members
  • 407 posts

Posted 03 April 2003 - 15:21

sorry ...
after looking into the dll, it just exports the functions
- DllCanUnloadNow
- DllGetClassObject
- DllMain
- DllRegisterServer
- DllUnregisterServer

Unlike user32.dll or kernel32.dll (which can be loaded and used for WINAPI calls like "GetDiskFreeSpaceA") msxml* dlls do not export the functions that could be used for creating DOM Documents and parsing and ...

Maybe it could be done with VisualBasic.
Search for XML on the forum, it has been discussed several times how to parse and write XML files, but no real answeres I could see.
Maybe you could write a personal message or email to the folks that looked for a solution?

good luck!! :)
Gruß / regards
Thomas

Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 03 April 2003 - 16:38

Why you guys trying to reinvent the wheel here instead of using an existing third party app. to do the XML parsing for you?
user posted image

vince_d

vince_d
  • Members
  • 17 posts

Posted 04 April 2003 - 07:51

What is this app ?

Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 04 April 2003 - 15:54

I know there are plenty out there, but since I personally don't use them, I can only suggest you do a search on Google.
user posted image

vince_d

vince_d
  • Members
  • 17 posts

Posted 04 April 2003 - 17:23

think you for your answer !!!!!!


In using msxml we don't  reinvent the wheel ;)
but the interface wasn't so easy


May be installshield could be develop this object  :D

Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 05 April 2003 - 00:55

Yeah, MSXML is one of the standard parsers which come to mind.

XML is certainly growing in popularity and general usage (just look at Office 2003).  I'm sure InstallShield will have to add built-in support for XML at some point much like it does for INIs now.

I'm not sure if IS Professional 7 has it, probably not, but I thinking IS Developer 8 might.
user posted image

Perotin

Perotin
  • Full Members
  • 407 posts

Posted 08 April 2003 - 14:26

As you might read in the docs, ini support is based on winapi functions (like GetPrivateProfileString).
There may be a way to wrap the msxml methods in IS rules ...
InstallShield will do anything but add XML support to IS 5.x    (oops, but also for IS 6.x I suppose)
???


Gruß / regards
Thomas