@@ -48,13 +48,14 @@ class Zend_Dom_Query
48
48
/**#@+
49
49
* Document types
50
50
*/
51
+ const DOC_DOM = 'docDom ' ;
51
52
const DOC_XML = 'docXml ' ;
52
53
const DOC_HTML = 'docHtml ' ;
53
54
const DOC_XHTML = 'docXhtml ' ;
54
55
/**#@-*/
55
56
56
57
/**
57
- * @var string
58
+ * @var string|DOMDocument
58
59
*/
59
60
protected $ _document ;
60
61
@@ -85,7 +86,7 @@ class Zend_Dom_Query
85
86
/**
86
87
* Constructor
87
88
*
88
- * @param null|string $document
89
+ * @param null|string|DOMDocument $document
89
90
* @param null|string $encoding
90
91
*/
91
92
public function __construct ($ document = null , $ encoding = null )
@@ -119,12 +120,15 @@ public function getEncoding()
119
120
/**
120
121
* Set document to query
121
122
*
122
- * @param string $document
123
+ * @param string|DOMDocument $document
123
124
* @param null|string $encoding Document encoding
124
125
* @return Zend_Dom_Query
125
126
*/
126
127
public function setDocument ($ document , $ encoding = null )
127
128
{
129
+ if ($ document instanceof DOMDocument) {
130
+ return $ this ->setDocumentDom ($ document );
131
+ }
128
132
if (0 === strlen ($ document )) {
129
133
return $ this ;
130
134
}
@@ -142,6 +146,17 @@ public function setDocument($document, $encoding = null)
142
146
return $ this ->setDocumentHtml ($ document , $ encoding );
143
147
}
144
148
149
+ /**
150
+ * @param DOMDocument $document
151
+ * @param string $encoding
152
+ */
153
+ public function setDocumentDom (DOMDocument $ document )
154
+ {
155
+ $ this ->_document = $ document ;
156
+ $ this ->_docType = self ::DOC_DOM ;
157
+ return $ this ;
158
+ }
159
+
145
160
/**
146
161
* Register HTML document
147
162
*
@@ -259,6 +274,9 @@ public function queryXpath($xpathQuery, $query = null)
259
274
}
260
275
$ type = $ this ->getDocumentType ();
261
276
switch ($ type ) {
277
+ case self ::DOC_DOM :
278
+ $ domDoc = $ this ->_document ;
279
+ break ;
262
280
case self ::DOC_XML :
263
281
try {
264
282
$ domDoc = Zend_Xml_Security::scan ($ document , $ domDoc );
0 commit comments