mn8 Language Reference | Index    

Tag

SUMMARY: ATTRIBUTES SUMMARY  NO ELEMENTS  CONSTRUCTORS SUMMARY  NO OPERATORS  METHODS SUMMARYDETAIL: ATTRIBUTE DETAILS  NO ELEMENTS  CONSTRUCTOR DETAILS  NO OPERATORS  METHOD DETAILS

Description

The Tag concept is related to the HTMLPage concept, but not only. The necesity for this concept appeared because of the lack of the Element concept to represent incomplete elements. Wrapping the content of a HTML page as elements would automaticaly create a DOM (Document Object Model) structure, which is not always desirable because of the computational overhead brought by this model.

Usage

example of how to create a Tag

            $tag TYPEOF Tag                                                                                                        
            $tag@name = "a"                                                                                                        
            $tag.setAttributes("href=http://www.nolimits.ro,title=Our homepage".getTokens(","))                                    
            PRINT $tag.toXML<a href="http://www.nolimits.ro" title="Our homepage">

example of how to parse HTML content.

            $html = "<a href=...>Our Homepage</a><br>"
            $val = Tag.extractTagsWithText( $html )
            EACH $elem IN $val DO [
                IF $elem.getConceptType == "Tag" THEN [
                    PRINT "TAG: " + $elem@name] ELSE [
                    PRINT $elem.getConceptType + ": " + $elem]]
                Tag : a
                String : Our homepage
                Tag : a
                Tag - br

Version: 0.1
Authors:Remus Pereni (http://neuro.nolimits.ro)
Location:
Inherits: Concept

Attribute List

 @isClosing TYPEOF Logical LABEL "isClosing"
 @name TYPEOF String LABEL "name"
top

Constructor List

create
top

Method List

static SeriesextractTags (String $extractFrom)
static SeriesextractTagsWithText (String $extractFrom)
SeriesgetAttributes
static StringgetStrippedText (String $extractFrom, Logical $withLinks)
setAttributes (Series $attributes)
StringtoTXT
StringtoXML
top
Methods inherited from: Concept
cloneConcept, extendsConcept, fromXML, getAllInheritedConcepts, getConceptAttribute, getConceptAttributeField, getConceptAttributeFields, getConceptAttributes, getConceptConstructors, getConceptElement, getConceptElementField, getConceptElementFields, getConceptElements, getConceptLabel, getConceptMethod, getConceptMethods, getConceptOperators, getConceptType, getErrorHandler, getInheritedConcepts, getResourceURI, hasConceptAttribute, hasConceptElement, hasConceptMethod, hasPath, isHidden, loadContent, setConceptLabel, setErrorHandler, setHidden, setShowEmpty, showEmpty, toTXT, toXML, setResourceURI

Detailed Attribute Info

@isClosing

Label:isClosing
Type:Logical
Is Static:false
Is Hidden:false
Show Empty:true

Can be TRUE or FALSE (default is TRUE) depending if the tag is close tag or not. As example a <a href="..."> tag would have the isClosing attribute showing FALSE and the </a> tag would have the isClosing attribute as TRUE. This influence the default XML rendering of the tag. Also if a tag is a closing tag it's attributes (if it has any) will be discarded at rendering.

top

@name

Label:name
Type:String
Is Static:false
Is Hidden:false
Show Empty:true

Contains a String representing the name of the Tag. For instance the<a href="..."> tag would render a name element of value "a". The HTML comments will produce a name of "!--".

top

Detailed Constructor Info

create

Constructs an empty Tag concept.

top

Detailed Method Info

static extractTags (String $extractFrom)
Parameters:
$extractFrom :A String concept from which the tags will be extracted.
Returns: Series

Method which will produce a Series of tags resulted from the parsing of the parameter string or stream. In case there is text data in the stream it will be rendered as String concepts in the resulted Series.

                $xml = "<person>" +\
                       "<name>" +\
                       "<firstname>Csaba</firstname>" +\
                       "<lastname>Szabo</lastname>" +\
                       "</name>" +\
                       "</person>"

                $tags = Tag.extractTags( $xml )

                EACH $tag IN $tags DO [
                    print $tag
                ]
                -- the result is --
                <person>
                <name>
                <firstname>
                </firstname>
                <lastname>
                </lastname>
                </name>
                </person>
            

top
static extractTagsWithText (String $extractFrom)
Parameters:
$extractFrom :A String concept from which the tags will be extracted.
Returns: Series

Method which will produce a Series of tags with text resulted from the parsing of the parameter string or stream. In case there is text data in the stream it will be rendered as String concepts in the resulted Series.

                $xml = "<person>" +\
                       "<name>" +\
                       "<firstname>Csaba</firstname>" +\
                       "<lastname>Szabo</lastname>" +\
                       "</name>" +\
                       "</person>"

                $tags = Tag.extractTagsWithText( $xml )

                EACH $tag IN $tags DO [
                    print $tag
                ]
                -- the result is --
                <person>
                <name>
                <firstname>
                Csaba
                </firstname>
                <lastname>
                Szabo
                </lastname>
                </name>
                </person>
            

top
getAttributes
Returns: Series

Returns a Series of Attributes related to this tag.

                $xml = "<person><name first='Csaba' last='Szabo' /></person>"
                $tags = Tag.extractTags( $xml )

                print $tags/2.getAttributes
                
                -- the result is --
                first: Csaba    last: Szabo
            

top
static getStrippedText (String $extractFrom, Logical $withLinks)
Parameters:
$extractFrom :A String concept from which the tags will be extracted.
$withLinks :If true returns the links value.
Returns: String

Returns a plain text rendering, without html tags, of the String given as parameter.

                $xml = "<person>" +\                                                                                                   
                       "<name first='Csaba' last='Szabo' />" +\                                                                       
                       "<address>Satu Mare</address>" +\                                                                              
                       "</person>"                                                                                                    
                                                                                                                       
                print Tag.getStrippedText( $xml, false )

                -- the result is --
                Satu Mare
            

top
setAttributes (Series $attributes)
Parameters:
$attributes :The attributes to be set.
Returns:

This method allows the addition of attributes to a Tag concept. The attributes can be specified as a Map having the name of the attributes as keys or as a Series containing Attribute concepts. The name and value of the attributes must be of String type.

                $tag TYPEOF Tag                                                                                                        
                $tag@name = "a"                                                                                                        

                $tag.setAttributes("href=http://www.nolimits.ro,title=Our homepage".getTokens(","))                                    

                PRINT $tag.toXML
                -- the result is -- 
                <a href="http://www.nolimits.ro" title="Our homepage">
            

top
toTXT
Returns: String

Returns a stream representing the simple text rendering of this concept.

                $tag TYPEOF Tag                                                                                                        
                $tag@name = "a"                                                                                                        
                $tag.setAttributes("href=http://www.nolimits.ro,title=Our homepage".getTokens(","))                                    

                PRINT $tag.toTXT

                -- the result is -- 
                <a href="http://www.nolimits.ro" title="Our homepage">
            

top
toXML
Returns: String

Returns a stream representing the XML rendering of this concept.

                $tag TYPEOF Tag                                                                                                        
                $tag@name = "a"                                                                                                        
                $tag.setAttributes("href=http://www.nolimits.ro,title=Our homepage".getTokens(","))                                    

                PRINT $tag.toTXT

                -- the result is -- 
                <a href="http://www.nolimits.ro" title="Our homepage">
            

top