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
- Install SWI-Prolog and its SGML package.
- Copy X-Prolog and optionally, the example to your
hard disk.
- Unpack the files,
tar xvfz
x-prolog.tgz
tar xvfz example.tgz Windows users can unpack it
with WinZip.
- Run SWI-Prolog.
- 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. |