DOORS DXL File Operation
In this article we will discuss DOORS DXL file operations.
In IBM Rational DOORS DXL (DOORS eXtension Language), file handling refers to the process of reading and writing files from within a DXL script. This allows the script to interact with files outside of the DOORS environment, such as text files, CSV files, and XML files.
Here are some examples of file handling tasks that can be performed in DOORS DXL:
- Reading data from a text file: The DXL script can open a text file and read the contents into a DOORS object or attribute.
- Writing data to a CSV file: The DXL script can create a new CSV file and write data from DOORS objects or attributes to the file in a comma-separated format.
- Parsing an XML file: The DXL script can open an XML file and extract data from specific elements or attributes within the file.
File input and output is done via streams in DXL (similar to C++). ‘>>’ reads the data from a stream and ‘<<‘ operator is used to write some data into the stream.
Overall, file handling in DOORS DXL provides a powerful tool for working with data outside of the DOORS environment and integrating DOORS with other systems or tools.
Write to a File
To write to a file in DOORS DXL, you can use the write function. The following example code is to show how to write to a file in DXL –
// www.TheCloudStrap.Com /************************************************************************ * $FILENAME: f1.dxl * $DESCRIPTION: File operations - Write * * NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved. * Software comes without any warranties and guarantees, is provided * as is and is not supported. Use this software at your own risk. * Authors resume no liabilities. * * Contact: admin {at} TheCloudStrap.com ************************************************************************/ // File Write operations Module m = current string f = "C:/sample_file.txt" Stream st_out = write f Object o string obj_txt = null string r_status = null string b_id = null st_out << "Object Text, Stakeholder_Req_Status, Build_ID\n" st_out << "---------------------------------------------------\n" for o in m do { obj_txt = o."Object Text" r_status = o."Stakeholder_Req_Status" b_id = o."Build_ID""" if(!null obj_txt) st_out << obj_txt ", " r_status ", " b_id "\n" } close st_out print "Done!\n"
Here is the DOORS module on which we ran the dxl code –
Here is the output –
Read from a File
Now, let’s read the same file (that we created in the previous example) and print out the content in the DXL output window –
// www.TheCloudStrap.Com /************************************************************************ * $FILENAME: f2.dxl * $DESCRIPTION: File operations - Read * * NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved. * Software comes without any warranties and guarantees, is provided * as is and is not supported. Use this software at your own risk. * Authors resume no liabilities. * * Contact: admin {at} TheCloudStrap.com ************************************************************************/ // File Read operations Module m = current string f = "C:/sample_file.txt" Stream st_inp = read f Object o string line = null print "print the content of the input fiule : \n" for(st_inp>>line; !end st_inp; st_inp>>line) { print line "\n" } close st_inp print "Done!\n"
Here is the output –
The output windows displays the content of the input file.
File Access
There are built-in functions in DXL that can be used to check various file parameters. For example, with the help of fileExists() function, you can determine if a file is already exists.
// www.TheCloudStrap.Com /************************************************************************ * $FILENAME: f3.dxl * $DESCRIPTION: File operations * * NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved. * Software comes without any warranties and guarantees, is provided * as is and is not supported. Use this software at your own risk. * Authors resume no liabilities. * * Contact: admin {at} TheCloudStrap.com ************************************************************************/ // bool isFileExists (string f_name) { Stat st = create (f_name) return (!null st) } // File Access string f = "C:/sample_file.txt" if (isFileExists(f)) { print "file exists.\n" } else { print "file does not exist.\n" } print "Done!\n"
Here is the output –
Since the ‘sample_file.txt’ already exists in C drive, the output prints ‘file exists’.
Conclusion
In this article we have explained how to write to a file and read from a file using DXL code.
This post was published by Admin.
Email: admin@TheCloudStrap.Com