可视化Prolog语言
Prolog Development Center A/S (PDC)

Convert  an HTML Text to a Prolog List

Written by Yasuhisa Matsumura

The program "HTML-to-List" reads an HTML text, converts it to a Prolog list, and then writes the list into a file.

How to Use the Program?

Click File | Open.

Thanks to the PDC

The program uses Editor and Configuration programs developed by the PDC.  The Editor is used only for displaying texts on the screen. The "Html to List" conversion is performed in the background.

Domains

The domains used are as follows:

     domains
        str = s(string); t(string).
        str_list = str*.

        attribute = a(string,string).
        attribute_list = attribute*.
        struc = t(string, attribute_list, html);
			s(string); c(string);
			e(string,attribute_list); x(string, attribute_list);
			ot(string, attribute_list); ct(string).
        html = struc*.

Conversion Example

<html>
  <HEAD>
  </HEAD>
  <body bgcolor="blue">
    Hi! How are you? <br>
    This is Yasu Matsumura.<br>
    <!-- This is a comment line -->
    <XmlEmptyTag />
  </body>
</html>

The above HTML text is converted to the following Prolog list:

[t("html",[],
  [t("head",[],
     []
   ),
   t("body",[a("bgcolor","blue")],
     [s("Hi! How are you?"),
      e("br",[]),
      s("This is Yasuihsa Matsumura"),
      c("!-- This is a comment line--"),
      x("xmlemptytag",[])
     ]
   )
   ]
 )
] 

Additional Explanations

The temporary domains that are used only in the conversion process are:

str= s(string); t(string),
str_list = str*,
ot(string, attribute_list) and
ct(string).

They are not included in the resultant domain html. Therefore, the list domain html is composed of:

attribute = a(string,string).
attribute_list = attribute*.
struc = t(string, attribute_list, html);
s(string); c(string);
e(string,attribute_list); x(string, attribute_list).
html = struc*.

The abbreviations t, s, c, etc., stand for:

  • t - tag,
  • s - string,
  • c - comment like <!-- comment -->,
  • e - empty tag,
  • x - xml empty tag like <xml_empty />,
  • ot - opening tag,
  • ct - closing tag.

The program:

  1. reads the file (e.g. index.html);
  2. converts it to a list;
  3. writes the list in the file "index.phtml".

The resulting file "index.phtml" includes only one list.

The list can be read as follows:   

domains
    attribute = a(string,string).
    attribute_list = attribute*.
    struc = t(string, attribute_list, html);
		 	s(string); c(string);
			e(string,attribute_list); x(string, attribute_list).
    html = struc*.

predicates
    read_list : (string FileName) -> html Html determ(i).

clauses
	read_list(FileName) = Html :-
		Input = inputStream_file::openFile(FileName),
		hasDomain(html, Html),
		Html = Input:read(),
		Input:close().

Download the project

 
Home | Company | News | Products Downloads | Shop | Support | Visual Prolog Features | Visual Prolog Compiler | FAQ | Tutorials | Examples | Knowledge Base | Discussion Forum | wiki | Site Map

Prolog Development Center A/S - H.J. Holst Vej 3-5C - 2605 Broendby, Denmark - Tel +45 3636 0000 - Fax +45 3636 0001 - sales@visual-prolog.com