Try to make hhvm test runs faster
[plcapi.git] / src / Helper / XMLParser.php
1 <?php
2
3 namespace PhpXmlRpc\Helper;
4
5 use PhpXmlRpc\PhpXmlRpc;
6 use PhpXmlRpc\Value;
7
8 /**
9  * Deals with parsing the XML.
10  */
11 class XMLParser
12 {
13     // used to store state during parsing
14     // quick explanation of components:
15     //   ac - used to accumulate values
16     //   stack - array with genealogy of xml elements names:
17     //           used to validate nesting of xmlrpc elements
18     //   valuestack - array used for parsing arrays and structs
19     //   lv - used to indicate "looking for a value": implements
20     //        the logic to allow values with no types to be strings
21     //   isf - used to indicate a parsing fault (2) or xmlrpc response fault (1)
22     //   isf_reason - used for storing xmlrpc response fault string
23     //   method - used to store method name
24     //   params - used to store parameters in method calls
25     //   pt - used to store the type of each received parameter. Useful if parameters are automatically decoded to php values
26     //   rt  - 'methodcall or 'methodresponse'
27     public $_xh = array(
28         'ac' => '',
29         'stack' => array(),
30         'valuestack' => array(),
31         'isf' => 0,
32         'isf_reason' => '',
33         'method' => false, // so we can check later if we got a methodname or not
34         'params' => array(),
35         'pt' => array(),
36         'rt' => '',
37     );
38
39     public $xmlrpc_valid_parents = array(
40         'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT'),
41         'BOOLEAN' => array('VALUE'),
42         'I4' => array('VALUE'),
43         'INT' => array('VALUE'),
44         'STRING' => array('VALUE'),
45         'DOUBLE' => array('VALUE'),
46         'DATETIME.ISO8601' => array('VALUE'),
47         'BASE64' => array('VALUE'),
48         'MEMBER' => array('STRUCT'),
49         'NAME' => array('MEMBER'),
50         'DATA' => array('ARRAY'),
51         'ARRAY' => array('VALUE'),
52         'STRUCT' => array('VALUE'),
53         'PARAM' => array('PARAMS'),
54         'METHODNAME' => array('METHODCALL'),
55         'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),
56         'FAULT' => array('METHODRESPONSE'),
57         'NIL' => array('VALUE'), // only used when extension activated
58         'EX:NIL' => array('VALUE'), // only used when extension activated
59     );
60
61     /**
62      * xml parser handler function for opening element tags.
63      */
64     public function xmlrpc_se($parser, $name, $attrs, $acceptSingleVals = false)
65     {
66         // if invalid xmlrpc already detected, skip all processing
67         if ($this->_xh['isf'] < 2) {
68             // check for correct element nesting
69             // top level element can only be of 2 types
70             /// @todo optimization creep: save this check into a bool variable, instead of using count() every time:
71             ///       there is only a single top level element in xml anyway
72             if (count($this->_xh['stack']) == 0) {
73                 if ($name != 'METHODRESPONSE' && $name != 'METHODCALL' && (
74                         $name != 'VALUE' && !$acceptSingleVals)
75                 ) {
76                     $this->_xh['isf'] = 2;
77                     $this->_xh['isf_reason'] = 'missing top level xmlrpc element';
78
79                     return;
80                 } else {
81                     $this->_xh['rt'] = strtolower($name);
82                 }
83             } else {
84                 // not top level element: see if parent is OK
85                 $parent = end($this->_xh['stack']);
86                 if (!array_key_exists($name, $this->xmlrpc_valid_parents) || !in_array($parent, $this->xmlrpc_valid_parents[$name])) {
87                     $this->_xh['isf'] = 2;
88                     $this->_xh['isf_reason'] = "xmlrpc element $name cannot be child of $parent";
89
90                     return;
91                 }
92             }
93
94             switch ($name) {
95                 // optimize for speed switch cases: most common cases first
96                 case 'VALUE':
97                     /// @todo we could check for 2 VALUE elements inside a MEMBER or PARAM element
98                     $this->_xh['vt'] = 'value'; // indicator: no value found yet
99                     $this->_xh['ac'] = '';
100                     $this->_xh['lv'] = 1;
101                     $this->_xh['php_class'] = null;
102                     break;
103                 case 'I4':
104                 case 'INT':
105                 case 'STRING':
106                 case 'BOOLEAN':
107                 case 'DOUBLE':
108                 case 'DATETIME.ISO8601':
109                 case 'BASE64':
110                     if ($this->_xh['vt'] != 'value') {
111                         //two data elements inside a value: an error occurred!
112                         $this->_xh['isf'] = 2;
113                         $this->_xh['isf_reason'] = "$name element following a {$this->_xh['vt']} element inside a single value";
114
115                         return;
116                     }
117                     $this->_xh['ac'] = ''; // reset the accumulator
118                     break;
119                 case 'STRUCT':
120                 case 'ARRAY':
121                     if ($this->_xh['vt'] != 'value') {
122                         //two data elements inside a value: an error occurred!
123                         $this->_xh['isf'] = 2;
124                         $this->_xh['isf_reason'] = "$name element following a {$this->_xh['vt']} element inside a single value";
125
126                         return;
127                     }
128                     // create an empty array to hold child values, and push it onto appropriate stack
129                     $curVal = array();
130                     $curVal['values'] = array();
131                     $curVal['type'] = $name;
132                     // check for out-of-band information to rebuild php objs
133                     // and in case it is found, save it
134                     if (@isset($attrs['PHP_CLASS'])) {
135                         $curVal['php_class'] = $attrs['PHP_CLASS'];
136                     }
137                     $this->_xh['valuestack'][] = $curVal;
138                     $this->_xh['vt'] = 'data'; // be prepared for a data element next
139                     break;
140                 case 'DATA':
141                     if ($this->_xh['vt'] != 'data') {
142                         //two data elements inside a value: an error occurred!
143                         $this->_xh['isf'] = 2;
144                         $this->_xh['isf_reason'] = "found two data elements inside an array element";
145
146                         return;
147                     }
148                 case 'METHODCALL':
149                 case 'METHODRESPONSE':
150                 case 'PARAMS':
151                     // valid elements that add little to processing
152                     break;
153                 case 'METHODNAME':
154                 case 'NAME':
155                     /// @todo we could check for 2 NAME elements inside a MEMBER element
156                     $this->_xh['ac'] = '';
157                     break;
158                 case 'FAULT':
159                     $this->_xh['isf'] = 1;
160                     break;
161                 case 'MEMBER':
162                     $this->_xh['valuestack'][count($this->_xh['valuestack']) - 1]['name'] = ''; // set member name to null, in case we do not find in the xml later on
163                     //$this->_xh['ac']='';
164                 // Drop trough intentionally
165                 case 'PARAM':
166                     // clear value type, so we can check later if no value has been passed for this param/member
167                     $this->_xh['vt'] = null;
168                     break;
169                 case 'NIL':
170                 case 'EX:NIL':
171                     if (PhpXmlRpc::$xmlrpc_null_extension) {
172                         if ($this->_xh['vt'] != 'value') {
173                             //two data elements inside a value: an error occurred!
174                             $this->_xh['isf'] = 2;
175                             $this->_xh['isf_reason'] = "$name element following a {$this->_xh['vt']} element inside a single value";
176
177                             return;
178                         }
179                         $this->_xh['ac'] = ''; // reset the accumulator
180                         break;
181                     }
182                 // we do not support the <NIL/> extension, so
183                 // drop through intentionally
184                 default:
185                     /// INVALID ELEMENT: RAISE ISF so that it is later recognized!!!
186                     $this->_xh['isf'] = 2;
187                     $this->_xh['isf_reason'] = "found not-xmlrpc xml element $name";
188                     break;
189             }
190
191             // Save current element name to stack, to validate nesting
192             $this->_xh['stack'][] = $name;
193
194             /// @todo optimization creep: move this inside the big switch() above
195             if ($name != 'VALUE') {
196                 $this->_xh['lv'] = 0;
197             }
198         }
199     }
200
201     /**
202      * Used in decoding xml chunks that might represent single xmlrpc values.
203      */
204     public function xmlrpc_se_any($parser, $name, $attrs)
205     {
206         $this->xmlrpc_se($parser, $name, $attrs, true);
207     }
208
209     /**
210      * xml parser handler function for close element tags.
211      */
212     public function xmlrpc_ee($parser, $name, $rebuildXmlrpcvals = true)
213     {
214         if ($this->_xh['isf'] < 2) {
215             // push this element name from stack
216             // NB: if XML validates, correct opening/closing is guaranteed and
217             // we do not have to check for $name == $currElem.
218             // we also checked for proper nesting at start of elements...
219             $currElem = array_pop($this->_xh['stack']);
220
221             switch ($name) {
222                 case 'VALUE':
223                     // This if() detects if no scalar was inside <VALUE></VALUE>
224                     if ($this->_xh['vt'] == 'value') {
225                         $this->_xh['value'] = $this->_xh['ac'];
226                         $this->_xh['vt'] = Value::$xmlrpcString;
227                     }
228
229                     if ($rebuildXmlrpcvals) {
230                         // build the xmlrpc val out of the data received, and substitute it
231                         $temp = new Value($this->_xh['value'], $this->_xh['vt']);
232                         // in case we got info about underlying php class, save it
233                         // in the object we're rebuilding
234                         if (isset($this->_xh['php_class'])) {
235                             $temp->_php_class = $this->_xh['php_class'];
236                         }
237                         // check if we are inside an array or struct:
238                         // if value just built is inside an array, let's move it into array on the stack
239                         $vscount = count($this->_xh['valuestack']);
240                         if ($vscount && $this->_xh['valuestack'][$vscount - 1]['type'] == 'ARRAY') {
241                             $this->_xh['valuestack'][$vscount - 1]['values'][] = $temp;
242                         } else {
243                             $this->_xh['value'] = $temp;
244                         }
245                     } else {
246                         /// @todo this needs to treat correctly php-serialized objects,
247                         /// since std deserializing is done by php_xmlrpc_decode,
248                         /// which we will not be calling...
249                         if (isset($this->_xh['php_class'])) {
250                         }
251
252                         // check if we are inside an array or struct:
253                         // if value just built is inside an array, let's move it into array on the stack
254                         $vscount = count($this->_xh['valuestack']);
255                         if ($vscount && $this->_xh['valuestack'][$vscount - 1]['type'] == 'ARRAY') {
256                             $this->_xh['valuestack'][$vscount - 1]['values'][] = $this->_xh['value'];
257                         }
258                     }
259                     break;
260                 case 'BOOLEAN':
261                 case 'I4':
262                 case 'INT':
263                 case 'STRING':
264                 case 'DOUBLE':
265                 case 'DATETIME.ISO8601':
266                 case 'BASE64':
267                     $this->_xh['vt'] = strtolower($name);
268                     /// @todo: optimization creep - remove the if/elseif cycle below
269                     /// since the case() in which we are already did that
270                     if ($name == 'STRING') {
271                         $this->_xh['value'] = $this->_xh['ac'];
272                     } elseif ($name == 'DATETIME.ISO8601') {
273                         if (!preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $this->_xh['ac'])) {
274                             error_log('XML-RPC: ' . __METHOD__ . ': invalid value received in DATETIME: ' . $this->_xh['ac']);
275                         }
276                         $this->_xh['vt'] = Value::$xmlrpcDateTime;
277                         $this->_xh['value'] = $this->_xh['ac'];
278                     } elseif ($name == 'BASE64') {
279                         /// @todo check for failure of base64 decoding / catch warnings
280                         $this->_xh['value'] = base64_decode($this->_xh['ac']);
281                     } elseif ($name == 'BOOLEAN') {
282                         // special case here: we translate boolean 1 or 0 into PHP
283                         // constants true or false.
284                         // Strings 'true' and 'false' are accepted, even though the
285                         // spec never mentions them (see eg. Blogger api docs)
286                         // NB: this simple checks helps a lot sanitizing input, ie no
287                         // security problems around here
288                         if ($this->_xh['ac'] == '1' || strcasecmp($this->_xh['ac'], 'true') == 0) {
289                             $this->_xh['value'] = true;
290                         } else {
291                             // log if receiving something strange, even though we set the value to false anyway
292                             if ($this->_xh['ac'] != '0' && strcasecmp($this->_xh['ac'], 'false') != 0) {
293                                 error_log('XML-RPC: ' . __METHOD__ . ': invalid value received in BOOLEAN: ' . $this->_xh['ac']);
294                             }
295                             $this->_xh['value'] = false;
296                         }
297                     } elseif ($name == 'DOUBLE') {
298                         // we have a DOUBLE
299                         // we must check that only 0123456789-.<space> are characters here
300                         // NOTE: regexp could be much stricter than this...
301                         if (!preg_match('/^[+-eE0123456789 \t.]+$/', $this->_xh['ac'])) {
302                             /// @todo: find a better way of throwing an error than this!
303                             error_log('XML-RPC: ' . __METHOD__ . ': non numeric value received in DOUBLE: ' . $this->_xh['ac']);
304                             $this->_xh['value'] = 'ERROR_NON_NUMERIC_FOUND';
305                         } else {
306                             // it's ok, add it on
307                             $this->_xh['value'] = (double)$this->_xh['ac'];
308                         }
309                     } else {
310                         // we have an I4/INT
311                         // we must check that only 0123456789-<space> are characters here
312                         if (!preg_match('/^[+-]?[0123456789 \t]+$/', $this->_xh['ac'])) {
313                             /// @todo find a better way of throwing an error than this!
314                             error_log('XML-RPC: ' . __METHOD__ . ': non numeric value received in INT: ' . $this->_xh['ac']);
315                             $this->_xh['value'] = 'ERROR_NON_NUMERIC_FOUND';
316                         } else {
317                             // it's ok, add it on
318                             $this->_xh['value'] = (int)$this->_xh['ac'];
319                         }
320                     }
321                     //$this->_xh['ac']=''; // is this necessary?
322                     $this->_xh['lv'] = 3; // indicate we've found a value
323                     break;
324                 case 'NAME':
325                     $this->_xh['valuestack'][count($this->_xh['valuestack']) - 1]['name'] = $this->_xh['ac'];
326                     break;
327                 case 'MEMBER':
328                     //$this->_xh['ac']=''; // is this necessary?
329                     // add to array in the stack the last element built,
330                     // unless no VALUE was found
331                     if ($this->_xh['vt']) {
332                         $vscount = count($this->_xh['valuestack']);
333                         $this->_xh['valuestack'][$vscount - 1]['values'][$this->_xh['valuestack'][$vscount - 1]['name']] = $this->_xh['value'];
334                     } else {
335                         error_log('XML-RPC: ' . __METHOD__ . ': missing VALUE inside STRUCT in received xml');
336                     }
337                     break;
338                 case 'DATA':
339                     //$this->_xh['ac']=''; // is this necessary?
340                     $this->_xh['vt'] = null; // reset this to check for 2 data elements in a row - even if they're empty
341                     break;
342                 case 'STRUCT':
343                 case 'ARRAY':
344                     // fetch out of stack array of values, and promote it to current value
345                     $currVal = array_pop($this->_xh['valuestack']);
346                     $this->_xh['value'] = $currVal['values'];
347                     $this->_xh['vt'] = strtolower($name);
348                     if (isset($currVal['php_class'])) {
349                         $this->_xh['php_class'] = $currVal['php_class'];
350                     }
351                     break;
352                 case 'PARAM':
353                     // add to array of params the current value,
354                     // unless no VALUE was found
355                     if ($this->_xh['vt']) {
356                         $this->_xh['params'][] = $this->_xh['value'];
357                         $this->_xh['pt'][] = $this->_xh['vt'];
358                     } else {
359                         error_log('XML-RPC: ' . __METHOD__ . ': missing VALUE inside PARAM in received xml');
360                     }
361                     break;
362                 case 'METHODNAME':
363                     $this->_xh['method'] = preg_replace('/^[\n\r\t ]+/', '', $this->_xh['ac']);
364                     break;
365                 case 'NIL':
366                 case 'EX:NIL':
367                     if (PhpXmlRpc::$xmlrpc_null_extension) {
368                         $this->_xh['vt'] = 'null';
369                         $this->_xh['value'] = null;
370                         $this->_xh['lv'] = 3;
371                         break;
372                     }
373                 // drop through intentionally if nil extension not enabled
374                 case 'PARAMS':
375                 case 'FAULT':
376                 case 'METHODCALL':
377                 case 'METHORESPONSE':
378                     break;
379                 default:
380                     // End of INVALID ELEMENT!
381                     // shall we add an assert here for unreachable code???
382                     break;
383             }
384         }
385     }
386
387     /**
388      * Used in decoding xmlrpc requests/responses without rebuilding xmlrpc Values.
389      */
390     public function xmlrpc_ee_fast($parser, $name)
391     {
392         $this->xmlrpc_ee($parser, $name, false);
393     }
394
395     /**
396      * xml parser handler function for character data.
397      */
398     public function xmlrpc_cd($parser, $data)
399     {
400         // skip processing if xml fault already detected
401         if ($this->_xh['isf'] < 2) {
402             // "lookforvalue==3" means that we've found an entire value
403             // and should discard any further character data
404             if ($this->_xh['lv'] != 3) {
405                 // G. Giunta 2006-08-23: useless change of 'lv' from 1 to 2
406                 //if($this->_xh['lv']==1)
407                 //{
408                 // if we've found text and we're just in a <value> then
409                 // say we've found a value
410                 //$this->_xh['lv']=2;
411                 //}
412                 // we always initialize the accumulator before starting parsing, anyway...
413                 //if(!@isset($this->_xh['ac']))
414                 //{
415                 //    $this->_xh['ac'] = '';
416                 //}
417                 $this->_xh['ac'] .= $data;
418             }
419         }
420     }
421
422     /**
423      * xml parser handler function for 'other stuff', ie. not char data or
424      * element start/end tag. In fact it only gets called on unknown entities...
425      */
426     public function xmlrpc_dh($parser, $data)
427     {
428         // skip processing if xml fault already detected
429         if ($this->_xh['isf'] < 2) {
430             if (substr($data, 0, 1) == '&' && substr($data, -1, 1) == ';') {
431                 // G. Giunta 2006-08-25: useless change of 'lv' from 1 to 2
432                 //if($this->_xh['lv']==1)
433                 //{
434                 //    $this->_xh['lv']=2;
435                 //}
436                 $this->_xh['ac'] .= $data;
437             }
438         }
439
440         return true;
441     }
442
443     /**
444      * xml charset encoding guessing helper function.
445      * Tries to determine the charset encoding of an XML chunk received over HTTP.
446      * NB: according to the spec (RFC 3023), if text/xml content-type is received over HTTP without a content-type,
447      * we SHOULD assume it is strictly US-ASCII. But we try to be more tolerant of non conforming (legacy?) clients/servers,
448      * which will be most probably using UTF-8 anyway...
449      * In order of importance checks:
450      * 1. http headers
451      * 2. BOM
452      * 3. XML declaration
453      * 4. guesses using mb_detect_encoding()
454      *
455      * @param string $httpHeader the http Content-type header
456      * @param string $xmlChunk xml content buffer
457      * @param string $encodingPrefs comma separated list of character encodings to be used as default (when mb extension is enabled)
458      * @return string
459      *
460      * @todo explore usage of mb_http_input(): does it detect http headers + post data? if so, use it instead of hand-detection!!!
461      */
462     public static function guessEncoding($httpHeader = '', $xmlChunk = '', $encodingPrefs = null)
463     {
464         // discussion: see http://www.yale.edu/pclt/encoding/
465         // 1 - test if encoding is specified in HTTP HEADERS
466
467         //Details:
468         // LWS:           (\13\10)?( |\t)+
469         // token:         (any char but excluded stuff)+
470         // quoted string: " (any char but double quotes and cointrol chars)* "
471         // header:        Content-type = ...; charset=value(; ...)*
472         //   where value is of type token, no LWS allowed between 'charset' and value
473         // Note: we do not check for invalid chars in VALUE:
474         //   this had better be done using pure ereg as below
475         // Note 2: we might be removing whitespace/tabs that ought to be left in if
476         //   the received charset is a quoted string. But nobody uses such charset names...
477
478         /// @todo this test will pass if ANY header has charset specification, not only Content-Type. Fix it?
479         $matches = array();
480         if (preg_match('/;\s*charset\s*=([^;]+)/i', $httpHeader, $matches)) {
481             return strtoupper(trim($matches[1], " \t\""));
482         }
483
484         // 2 - scan the first bytes of the data for a UTF-16 (or other) BOM pattern
485         //     (source: http://www.w3.org/TR/2000/REC-xml-20001006)
486         //     NOTE: actually, according to the spec, even if we find the BOM and determine
487         //     an encoding, we should check if there is an encoding specified
488         //     in the xml declaration, and verify if they match.
489         /// @todo implement check as described above?
490         /// @todo implement check for first bytes of string even without a BOM? (It sure looks harder than for cases WITH a BOM)
491         if (preg_match('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlChunk)) {
492             return 'UCS-4';
493         } elseif (preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlChunk)) {
494             return 'UTF-16';
495         } elseif (preg_match('/^(\xEF\xBB\xBF)/', $xmlChunk)) {
496             return 'UTF-8';
497         }
498
499         // 3 - test if encoding is specified in the xml declaration
500         // Details:
501         // SPACE:         (#x20 | #x9 | #xD | #xA)+ === [ \x9\xD\xA]+
502         // EQ:            SPACE?=SPACE? === [ \x9\xD\xA]*=[ \x9\xD\xA]*
503         if (preg_match('/^<\?xml\s+version\s*=\s*' . "((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))" .
504             '\s+encoding\s*=\s*' . "((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",
505             $xmlChunk, $matches)) {
506             return strtoupper(substr($matches[2], 1, -1));
507         }
508
509         // 4 - if mbstring is available, let it do the guesswork
510         // NB: we favour finding an encoding that is compatible with what we can process
511         if (extension_loaded('mbstring')) {
512             if ($encodingPrefs) {
513                 $enc = mb_detect_encoding($xmlChunk, $encodingPrefs);
514             } else {
515                 $enc = mb_detect_encoding($xmlChunk);
516             }
517             // NB: mb_detect likes to call it ascii, xml parser likes to call it US_ASCII...
518             // IANA also likes better US-ASCII, so go with it
519             if ($enc == 'ASCII') {
520                 $enc = 'US-' . $enc;
521             }
522
523             return $enc;
524         } else {
525             // no encoding specified: as per HTTP1.1 assume it is iso-8859-1?
526             // Both RFC 2616 (HTTP 1.1) and 1945 (HTTP 1.0) clearly state that for text/xxx content types
527             // this should be the standard. And we should be getting text/xml as request and response.
528             // BUT we have to be backward compatible with the lib, which always used UTF-8 as default...
529             return PhpXmlRpc::$xmlrpc_defencoding;
530         }
531     }
532
533     /**
534      * Helper function: checks if an xml chunk as a charset declaration (BOM or in the xml declaration)
535      *
536      * @param string $xmlChunk
537      * @return bool
538      */
539     public static function hasEncoding($xmlChunk)
540     {
541         // scan the first bytes of the data for a UTF-16 (or other) BOM pattern
542         //     (source: http://www.w3.org/TR/2000/REC-xml-20001006)
543         if (preg_match('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlChunk)) {
544             return true;
545         } elseif (preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlChunk)) {
546             return true;
547         } elseif (preg_match('/^(\xEF\xBB\xBF)/', $xmlChunk)) {
548             return true;
549         }
550
551         // test if encoding is specified in the xml declaration
552         // Details:
553         // SPACE:         (#x20 | #x9 | #xD | #xA)+ === [ \x9\xD\xA]+
554         // EQ:            SPACE?=SPACE? === [ \x9\xD\xA]*=[ \x9\xD\xA]*
555         if (preg_match('/^<\?xml\s+version\s*=\s*' . "((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))" .
556             '\s+encoding\s*=\s*' . "((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",
557             $xmlChunk, $matches)) {
558             return true;
559         }
560
561         return false;
562     }
563 }