The API (Application Program Interface)

(For Python Programers)

If you wish to use rtf2xml as part of a larger python program rather than from the command line, first import the rtf2xml.ParseRtf module:

        import rtf2xml.ParseRtf
    

Next, create a parsing object:

        
    parse_obj =rtf2xml.ParseRtf.ParseRtf(   
            in_file = 'in.rtf', 
    )
    

The in_file variable should point to the path of the RTF file. I'll cover the optional parameters below.

Finally, convert the document by calling the method 'parse_rtf'.

        try:
            exit_level = parse_obj.parse_rtf()
        except rtf2xml.ParseRtf.InvalidRtfException, msg:
            pass
        # catches just *some* bugs
        # Need to do more work on it
        except rtf2xml.ParseRtf.RtfInvalidCodeException, msg:
            pass
    

The two exception classes are InvalideRtfException and RtfInvalidCodeException. The second of these two is not yet fully implemented. It will catch some of the bugs in the code, but not all of them. If you set the level to something higher than 3, that means the whole script will now quit. In the future, you will be able to stop the script from quitting by catching the second exception. For now, in order to avoid an unwanted quit, set the level at 1 or 2.

If there are no errors, the exit level will be 0. Otherwise, it will be 1. Note that I am in the process of getting rid of the exit_level in favor of throwing exceptions. For now, use a combination of both the RtfInvalidException class and the level.

Here is an example of a complete script that uses the rtf2xml modules. I have made minimial comments on the parameters one can use when call ing the 'parse_rtf' method. For more details, see the options in the full documentation, use.

python_example.py