Main | Team | Papers | Download | Links


Download

You need to install (if you do not already have) SWI-Prolog and make sure that the SGML package is working.

[2002-08-09] X-Prolog and an example.

How to run X-Prolog

  1. Install SWI-Prolog and its SGML package.
  2. Copy X-Prolog and optionally, the example to your hard disk.
  3. Unpack the files,

    tar xvfz x-prolog.tgz
    tar xvfz example.tgz

    Windows users can unpack it with WinZip.

  4. Run SWI-Prolog.
  5. Consult the file x-prolog.pl.

How does it work

 X-Prolog provides you with 3 predicates:

  • xml_to_prolog(XMLFile,DTDFile,XMLTerm,DTDType): Translates a XML file to a Prolog term.
    • XMLFile : name of the input xml document file.
    • DTDFile: name of the input DTD file.
    • XMLTerm: Prolog term resulting from processing XMLFile.
    • DTDType: Internal type representation for DTD in DTDFile.
  • prolog_to_xml(DTDFile,DTDType,XMLTerm,XMLFile): Translates a Prolog term to a XML file.
    • DTDFile: name of the output DTD file.
    • DTDType: Internal type representation for DTD in DTDFile.
    • XMLTerm: Prolog term resulting from processing XMLFile.
    • XMLFile : name of the output xml document file (based on XMLTerm).
  • x-compile(FileName): Compiles the program verifying types.
    • FileName: Prolog program to check and compile.

Your program must have one main predicate (the name is not important) where you use xml_to_prolog and prolog_to_xml and between these you must put your processing predicate. For example:

prog(FileXML1,XMLTerm1,FileXML2,XMLTerm2):-
                                xml_to_prolog(FileXML1,'address.dtd',XMLTerm1,TypeDTD1),
                                process(XMLTerm1,XMLTerm2),
                                prolog_to_xml('address2.dtd',TypeDTD2,XMLTerm2,FileXML2).
....
 

Now, you just have to process the XMLTerm1 as you want, resulting in XMLTerm2. The type system checks program validity with respect to the DTDs.

 

Contact us