awsHTML class

This class is a tool that can be used to parse HTML files in a intuitive manner using chainability. The DOMNodeList can be easily accesed though results property of the awsHTML instance.

Sample code: $app = new awsHTML(file_get_contents("appTemplate.xml"));
$app->q("//a[@id='id_of_entity']")-> each("do_something_callbackFunction")-> removeAttr("SOME_ATTRIBUTE")-> attr("ANOTHER_ATTR","VALUE")-> append("HTML_FRAGMENT")-> prepend("HTML_FRAGMENT")-> q("something_else_xpath")-> replace("HTML_FRAGMENT")-> q("something_else_xpath")-> removeChilds()-> append("HTML_FRAGMENT");
echo $app->content();

- Once with AWS XMS 1.0 beta 10 two functions were introduced: awsHTML::cssq (css query) and awsHTML::csse (css evaluate);
In previous versions only xpath selectors were allowed. Once with these new functions you can use css selectors as well;
- XPATH to CSS transformer is provided by the Zend_Dom_Query_Css2Xpath class of ZendFramework-1.10.8;
- Once with AWS XMS 1.0 beta 10 a default context is set up, once you create an instance of awsHTML; this context depends on the type of parameter used for awsHTML constructor; See awsHTML::__constructor documentation;

Class structure
  • awsHTML extends awsCommonXML implements awsHTMLInterface
    • Properties
    • Methods
      • awsHTML __construct( mixed $from) more...
      • void addMeta( string $name, string $content)
      • void addScript( string $url, string $run)
      • void addStyle( string $url, string $media, string $media)
      • DOMNode body()
      • string bodyContent()
      • string documentContent()
      • DOMNodeList getLinks()
      • DOMNodeList getScripts()
      • DOMNodeList getStyles()
      • DOMNode head()
      • string headContent()
      • void setDescription( string $description)
      • void setKeywords( string $keywords)
        • inherited from awsCommonXML
          • awsHTML after( string $htmlString)
          • awsHTML append( string $htmlString)
          • awsHTML attr( string $name, string $value)
          • awsHTML before( string $htmlString)
          • string content()
          • void copyElement( DOMNode $domElement, DOMNode $targetNode, string $newNodeName, bool $skipChilds = false, bool $skipAttributes = false)
          • awsHTML csse( string $cssQuery, DOMNode $context)
          • Run a css evaluate over the context
          • awsHTML cssq( string $cssQuery, DOMNode $context)
          • Run a css query over the context
          • string documentContent()
          • awsHTML e( string $xpathQuery, DOMNode $context)
          • Run a xpath evaluate over the context
          • awsHTML each( string $callbackFunction, mixed param1, mixed param2,..., mixed paramn)
          • Executes a function for each DOMNode of the last query; Function can be either an already defined one or an anonymous (lambda style) function (See create_function);
            Default parameter of the function, when called, is $el, the current DOMNode in DOMNodeList (results property or last query result);
            Since AWS XMS 1.0 beta 10 you can specify as many parameters you need as these will be passed to the function when executed;

            function someFunction(&el,$name,$value)

            function otherFunction(&el)


            echo $domNodeListItem->nodeName." = ".$domNodeListItem->nodeValue;


            $parser = new awsHTML($GLOBALS["HTMLPARSER"]->cssq("#menu")->results->item(0));
            $liParser = new awsHTML($parser->q("descendant::li")->results->item(0));


            echo $liParser->results->item(0)->getAttribute("ATTRNAME");
          • DOMNode filter()
          • DOMNode first()
          • Return first DOMNode of the last query
          • DOMNode getRootElement()
          • DOMNode iterate()
          • Iterates through the results of the last query; Current node is thecurrent property of the awsHTML object;
            To be used with while
          • DOMNode last()
          • Return last DOMNode of the last query
          • awsHTML prepend( string $htmlString)
          • awsHTML q( string $xpathQuery, DOMNode $context)
          • Run a xpath query over the context
          • awsHTML removeAttr( string $name)
          • awsHTML removeChilds()
          • awsHTML replace( string $htmlString)
          • awsHTML replaceContent( string $htmlString)
          • string resultsAsSource()
          • Retrieve the source of all DOMNodes of the last query;
          • DOMDocumentFragment resultsAsDocumentFragment()
          • Retrieve all DOMNodes of the last query as DOMDocumentFragment;
          • mixed text([ string $newText])
          • Parameter:
            string $newText - optional

            - When called like $an_awsHTML->text() will return the text content of all nodes of the last query;

            - When called like $an_awsHTML->text("some text") will set text content of all nodes of the last query;
          • awsHTML to($variable)
          • Assigns the results (as DOMNodeList) of the last query to the variable passed as parameter
            $someVar = "";
            foreach($someVar as $domNodeListItem)
            echo $domNodeListItem->nodeName." = ".$domNodeListItem->nodeValue;