.. _zend.dom.query: Zend\\Dom\\Query ================ ``Zend\Dom\Query`` provides mechanisms for querying *XML* and (X) *HTML* documents utilizing either XPath or *CSS* selectors. It was developed to aid with functional testing of *MVC* applications, but could also be used for rapid development of screen scrapers. *CSS* selector notation is provided as a simpler and more familiar notation for web developers to utilize when querying documents with *XML* structures. The notation should be familiar to anybody who has developed Cascading Style Sheets or who utilizes Javascript toolkits that provide functionality for selecting nodes utilizing *CSS* selectors (`Prototype's $$()`_ and `Dojo's dojo.query`_ were both inspirations for the component). .. _zend.dom.query.operation: Theory of Operation ------------------- To use ``Zend\Dom\Query``, you instantiate a ``Zend\Dom\Query`` object, optionally passing a document to query (a string). Once you have a document, you can use either the ``query()`` or ``queryXpath()`` methods; each method will return a ``Zend\Dom\NodeList`` object with any matching nodes. The primary difference between ``Zend\Dom\Query`` and using `DOMDocument`_ + `DOMXPath`_ is the ability to select against *CSS* selectors. You can utilize any of the following, in any combination: - **element types**: provide an element type to match: 'div', 'a', 'span', 'h2', etc. - **style attributes**: *CSS* style attributes to match: '``.error``', '``div.error``', '``label.required``', etc. If an element defines more than one style, this will match as long as the named style is present anywhere in the style declaration. - **id attributes**: element ID attributes to match: '#content', 'div#nav', etc. - **arbitrary attributes**: arbitrary element attributes to match. Three different types of matching are provided: - **exact match**: the attribute exactly matches the string: 'div[bar="baz"]' would match a div element with a "bar" attribute that exactly matches the value "baz". - **word match**: the attribute contains a word matching the string: 'div[bar~="baz"]' would match a div element with a "bar" attribute that contains the word "baz". '
Lorem ipsum
|