Нет описания

XMLParser.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace AliyunMNS\Common;
  3. class XMLParser
  4. {
  5. /**
  6. * Most of the error responses are in same format.
  7. */
  8. static function parseNormalError(\XMLReader $xmlReader) {
  9. $result = array('Code' => NULL, 'Message' => NULL, 'RequestId' => NULL, 'HostId' => NULL);
  10. while ($xmlReader->Read())
  11. {
  12. if ($xmlReader->nodeType == \XMLReader::ELEMENT)
  13. {
  14. switch ($xmlReader->name) {
  15. case 'Code':
  16. $xmlReader->read();
  17. if ($xmlReader->nodeType == \XMLReader::TEXT)
  18. {
  19. $result['Code'] = $xmlReader->value;
  20. }
  21. break;
  22. case 'Message':
  23. $xmlReader->read();
  24. if ($xmlReader->nodeType == \XMLReader::TEXT)
  25. {
  26. $result['Message'] = $xmlReader->value;
  27. }
  28. break;
  29. case 'RequestId':
  30. $xmlReader->read();
  31. if ($xmlReader->nodeType == \XMLReader::TEXT)
  32. {
  33. $result['RequestId'] = $xmlReader->value;
  34. }
  35. break;
  36. case 'HostId':
  37. $xmlReader->read();
  38. if ($xmlReader->nodeType == \XMLReader::TEXT)
  39. {
  40. $result['HostId'] = $xmlReader->value;
  41. }
  42. break;
  43. }
  44. }
  45. }
  46. return $result;
  47. }
  48. }
  49. ?>