awsXML

Back
This class is a tool that can be used to parse XML files in a intuitive manner using chainability. The DOMNodeList can be easily accesed though results property of the awsXML instance.
Class structure
  • awsXML extends awsCommonXML implements awsXMLInterface
    • Properties
    • Methods
      • awsXML __construct( mixed $from, string $encoding) more...
      • string content()
      • string contentAs($outputType)
        • inherited from awsCommonXML
          • awsXML after( string $htmlString)
          • awsXML append( string $htmlString)
          • awsXML attr( string $name, string $value)
          • awsXML before( string $htmlString)
          • string content()
          • void copyElement( DOMNode $domElement, DOMNode $targetNode, string $newNodeName, bool $skipChilds = false, bool $skipAttributes = false)
          • awsXML csse( string $cssQuery, DOMNode $context)
          • Run a css evaluate over the context
          • awsXML cssq( string $cssQuery, DOMNode $context)
          • Run a css query over the context
          • string documentContent()
          • awsXML e( string $xpathQuery, DOMNode $context)
          • Run a xpath evaluate over the context
          • awsXML 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;

            Example:
            function someFunction(&el,$name,$value)
            {$el->setAttribute($name,$value);}

            function otherFunction(&el)
            {$el->setAttribute("anAttribute","value");}

            $an_awsXMLInstance->q("xpathSelector")
            ->each("someFunction","newAttribute","value")
            ->cssq("cssSelector")->each("otherFunction");

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

            Or:

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

            $liParser->q("a")->each(create_function('&$el,$name,$value','$el->setAttribute($name,$value);'),"ATTRNAME","ATTRVAL");

            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 awsXML object;
            To be used with while
          • DOMNode last()
          • Return last DOMNode of the last query
          • awsXML prepend( string $htmlString)
          • awsXML q( string $xpathQuery, DOMNode $context)
          • Run a xpath query over the context
          • awsXML removeAttr( string $name)
          • awsXML removeChilds()
          • awsXML replace( string $htmlString)
          • awsXML 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_awsXML->text() will return the text content of all nodes of the last query;

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