InstallShield: some functions used to write XML and ini configuration files

Source: Internet
Author: User

InstallShield: some functions used to write XML and ini configuration files

Some functions of InstallShield for writing XML and ini configuration files

InstallShield uses the DOM Document Object Model for operating XML, which is better.

Prototype createxml (string );
Prototype deltexmlnode (string );
Prototype updatexmlnode (string );
Prototype insertxmlnode (string );

// Create an XML document
Function createxml (szfile)
Object objxml;
String strxml;
Begin
// Start creating an XML document
Set objxml = Createobject ("MSXML. domdocument"); // create a DOM object
If (isobject (objxml) = false) then
MessageBox ("error, the system does not support DOM objects", severe );
Endif;
Objxml. async = false;
/// R/N is the line feed to make the content more beautiful.
Strxml = "<? XML version =/"1.0/" encoding =/"UTF-8/"?> /R/N"
+ "<Inventory>/R/N"
+ "<Book> <title src =/" www/"> one </title> <price> 1.0 </price> </book>/R/N"
+ "<Book> <title> two </title> <price> 2.0 </price> </book>/R/N"
+ "<Book> <title> three </title> <price> 3.0 </price> </book>/R/N"
+ "</Inventory>/R/N ";
Objxml. loadxml (strxml); // you can use a snippet to easily obtain an XML document.
Objxml. Save (szfile); // save
Set objxml = nothing;
End;

// Insert a node Value
Function insertxmlnode (szfile)
Object objxml;
Object objroot, objnode;
Object objbook, objtitle, objattributenode;
Begin
Set objxml = Createobject ("MSXML. domdocument"); // create a DOM object
If (isobject (objxml) = false) then
MessageBox ("error, the system does not support DOM objects", severe );
Endif;
Objxml. async = false;
Objxml. Load (szfile); // load the original XML file
Set objroot = objxml.doc umentelement; // get the root node
Set objbook = objxml. createelement ("book ");
// Objbook. Text = "free ";
Set objtitle = objxml. createelement ("title ");
Objtitle. Text = "4 ";
Set objattributenode = objxml. createnode ("attribute", "src ","");
Objattributenode. Text = "ww ";
Objtitle. setattributenode (objattributenode); // Add an attribute node

Objbook. appendchild (objtitle );
Objroot. appendchild (objbook); // Add a node
Objxml. Save (szfile); // save

Set objbook = nothing;
Set objtitle = nothing;
Set objxml = nothing;
End;

// Update a node Value
Function updatexmlnode (szfile)
Object objxml;
Object objroot, objnode;
Begin
Set objxml = Createobject ("MSXML. domdocument"); // create a DOM object
If (isobject (objxml) = false) then
MessageBox ("error, the system does not support DOM objects", severe );
Endif;
Objxml. async = false;
Objxml. Load (szfile); // load the original XML file
Set objroot = objxml.doc umentelement; // get the root node
// MessageBox (objroot. XML, severe); // output all nodes for testing
Set objnode = objroot. selectsinglenode ("book/Title"); // search for the title Node
// MessageBox (objnode. Text, severe); // output its value
Objnode. Text = "hello"; // change the value
Objxml. Save (szfile); // save
Set objnode = nothing;
Set objxml = nothing;
End;

// Delete a node
Function deltexmlnode (szfile)
Object objxml;
Object objroot, objnode;
Begin
Set objxml = Createobject ("MSXML. domdocument"); // create a DOM object
If (isobject (objxml) = false) then
MessageBox ("error, the system does not support DOM objects", severe );
Endif;
Objxml. async = false;
Objxml. Load (szfile); // load the original XML file
Set objroot = objxml.doc umentelement; // get the root node
// MessageBox (objroot. XML, severe); // output all nodes for testing
Set objnode = objroot. selectsinglenode ("book/Title"); // search for the title Node
// MessageBox (objnode. Text, severe); // output its value
Objnode. parentnode. removechild (objnode); // Delete the node
Objxml. Save (szfile); // save
Set objnode = nothing;
Set objxml = nothing;
End;

// Some functions that operate ini text files

Prototype createini (string );
Prototype readini (string );
Prototype selecini (string, string );
Prototype inserini (string, string );

// Create the ini configuration file
Function createini (szfile)
Hwnd file; // file handle
Begin
Openfilemode (file_mode_append); // write data from the end in the open mode.
Createfile (file, "C: //", szfile); // create a file
Writeline (file, "this is one line"); // write a row
Writeline (file, "this is two line ");
Closefile (File); // close the file
End;

// Read Configuration
Function readini (szfile)
Hwnd file;
String szline;
Begin
Openfilemode (file_mode_normal); // read data from the beginning in the open mode.
Openfile (file, "C: //", szfile); // create a file
Getline (file, szline );
MessageBox (szline, severe );
Closefile (File); // close the file
End;

// Search for a row
Function selecini (szfile, selectstr)
String szline;
Number sznum;
Begin
Openfilemode (file_mode_normal); // Open Mode
Filegrep (szfile, selectstr, szline, sznum, restart );
// MessageBox (szline, severe); // the pop-up content
Return sznum; // return the row number.
End;

// Insert a row
Function inserini (szfile, selectstr)
Number sznum;
String STR;
Begin
Sznum = selecini (szfile, selectstr); // retrieve the row number
Numtostr (STR, sznum );
MessageBox (STR, severe); // row number
Fileinsertline (szfile, "the free line", sznum, after );
End;

//////////////////////////////////////// //////////////////
//
// Rewrite the file attribute to remove the read-only or hidden attribute! (This is a function written by someone else)
//
//////////////////////////////////////// /////////////////////

Export prototype changefileinfo (string );
Function changefileinfo (filenames)
String szfiles, szpath, svresult;
Number nvresult;
Begin

If (getfileinfo (filenames, file_attribute, nvresult, svresult) = 0) then;

If (nvresult = file_attr_normal) then
// Do nothing;
Else
If (file_attr_hidden & nvresult) then
Setfileinfo (filenames, file_attribute, file_attr_normal ,"");
Endif;
If (file_attr_readonly & nvresult) then
Setfileinfo (filenames, file_attribute, file_attr_normal ,"");
Endif;
Endif;
Endif;
End;

<A piece of code found online is very useful>
In the InstallShield script, the content that needs to be added is displayed in the prompt box before the file copy starts. It is a good habit to confirm the content set by the user...
Listaddstring (liststartcopy, "target path:" + installdir, after );
Listaddstring (liststartcopy, "", after );
Listaddstring (liststartcopy, "you have selected the following components:", after );
List = listcreate (stringlist );
Featurelistitems (media, "services", list );
Nresult = listgetfirststring (list, svitem );
While(Nresult! = End_of_list)
IfFeatureisitemselected (Media, svitem)Then
Featuregetdata (Media, svitem, feature_field_displayname, nvresult, svresult );
Listaddstring (liststartcopy, "" + svresult, after );
Endif;
Nresult = listgetnextstring (list, svitem );
Endwhile;
Listdestroy (list );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.