Re: HTML processing

Bill Yerazunis <[email protected]>
Newsgroups gmane.mail.spam.crm114
Message-ID <[email protected]>
   From: "Trever L. Adams" <[email protected]>

   I am thinking of using CRM114 for a project. I have a few questions,
   only one of which do I think I know the answer to.

   1) Can CRM114 be used as a library or do I have to have it run as a
   daemon running my code and connect via sockets? (I believe the answer is
   the latter.)

The latter. 

Why?  Because CRM114's internal data model is that of overlapped
strings; no other language (that I know of) allows such flagrant
abuse of strings, let alone encourages this behavior as "good style".


   2) Is it possible to process HTML such that I remove all HTML tags BUT
   keep the content of the CONTENT part of META tags and ALT and TITLE
   content from <IMG>? If so, how?

Yes.

I assume you mean something like this; turn:

   <b> foo </b>
   <le> bar </le>
   <title> My web page </title>
   <img src="./my_photo.jpg" alt="What I look like" title="My Portrait">
   <meta NAME="description" CONTENT="user"> I assume there is text here
   <p>
   This is my text
   <p>

should get turned into:

   foo
   bar
   My web page
   alt="What I look like" title="My Portrait"
   NAME="description" CONTENT="user" I assume there is text here
   This is my text
   
which is moderately easy to do.  I guess it should not be
more than fifteen lines.

Try this...  DANGER ***UNTESTED CODE*** DANGER !!!

{
    #  Turn all of the content of META tags into inline text
    {
	match <nocase> /<meta ([^>]*)>/ (:whole_meta_tag: :meta_txt:)
	alter (:whole_meta_tag:) /:*:meta_txt:/
	liaf
    }
    #  Keep only the alt and title sections of an IMG tag
    {
	isolate (:img_txt: :alt_txt:)
	match <nocase>  /<img ([^>]*)>/  (:whole_img_tag:)
	{
	    match <nocase> [:whole_img_tag:] /img=[[:graph:]]*/ (:img_txt:)
	}
	{
	    match <nocase> [:whole_img_tag:] /alt=[[:graph:]]*/ (:alt_txt:)
	}
  	alter (:whole_img_tag:) / :*:img_txt: :*:alt_txt: /
	liaf
    }
    #   Get rid of every other tag, without mercy!
    {
	match <nocase> /<[^>]*>/ (:some_tag:)
	alter (:some_tag:) //
	liaf
    }
    accept
}

That at least is a good start on it.

     - Bill Yerazunis

    

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.