|
1 | 1 | <?php
|
| 2 | + |
2 | 3 | // Distributed by license from CardinalCommerce Corporation
|
3 | 4 | /////////////////////////////////////////////////////////////////////////////////////////////
|
4 | 5 | // CardinalCommerce (http://www.cardinalcommerce.com)
|
|
11 | 12 | //
|
12 | 13 | /////////////////////////////////////////////////////////////////////////////////////////////
|
13 | 14 |
|
14 |
| - class XMLParser{ |
15 |
| - |
16 |
| - var $xml_parser; |
17 |
| - var $deseralizedResponse; |
18 |
| - var $elementName; |
19 |
| - var $elementValue; |
20 |
| - |
21 |
| - ///////////////////////////////////////////////////////////////////////////////////////////// |
22 |
| - // Function XMLParser() |
23 |
| - // |
24 |
| - // Initialize the XML parser. |
25 |
| - ///////////////////////////////////////////////////////////////////////////////////////////// |
26 |
| - |
27 |
| - function __construct() { |
28 |
| - $this->xml_parser = xml_parser_create(); |
29 |
| - } |
30 |
| - |
31 |
| - ///////////////////////////////////////////////////////////////////////////////////////////// |
32 |
| - // Function startElement(parser, name, attribute) |
33 |
| - // |
34 |
| - // Start Tag Element Handler |
35 |
| - ///////////////////////////////////////////////////////////////////////////////////////////// |
36 |
| - |
37 |
| - function startElement($parser, $name, $attrs='') { |
38 |
| - $this->elementName= $name; |
39 |
| - |
40 |
| - } |
41 |
| - |
42 |
| - ///////////////////////////////////////////////////////////////////////////////////////////// |
43 |
| - // Function elementData(parser, data) |
44 |
| - // |
45 |
| - // Element Data Handler |
46 |
| - ///////////////////////////////////////////////////////////////////////////////////////////// |
47 |
| - |
48 |
| - function elementData($parser, $data) { |
49 |
| - $this->elementValue .= $data; |
50 |
| - |
51 |
| - } |
52 |
| - |
53 |
| - ///////////////////////////////////////////////////////////////////////////////////////////// |
54 |
| - // Function endElement(name, value) |
55 |
| - // |
56 |
| - // End Tag Element Handler |
57 |
| - ///////////////////////////////////////////////////////////////////////////////////////////// |
58 |
| - |
59 |
| - function endElement($parser, $name) { |
60 |
| - |
61 |
| - $this->deserializedResponse[$this->elementName]= $this->elementValue; |
62 |
| - $this->elementName = ""; |
63 |
| - $this->elementValue = ""; |
64 |
| - } |
65 |
| - |
66 |
| - ///////////////////////////////////////////////////////////////////////////////////////////// |
67 |
| - // Function deserialize(xmlString) |
68 |
| - // |
69 |
| - // Deserilize the XML reponse message and add each element to the deseralizedResponse collection. |
70 |
| - // Once complete, then each element reference will be available using the getValue function. |
71 |
| - ///////////////////////////////////////////////////////////////////////////////////////////// |
72 |
| - |
73 |
| - function deserializeXml($responseString) { |
74 |
| - |
75 |
| - xml_set_object($this->xml_parser, $this); |
76 |
| - xml_parser_set_option($this->xml_parser,XML_OPTION_CASE_FOLDING,FALSE); |
77 |
| - xml_set_element_handler($this->xml_parser, "startElement", "endElement"); |
78 |
| - xml_set_character_data_handler($this->xml_parser, "elementData"); |
79 |
| - |
80 |
| - if (!xml_parse($this->xml_parser, $responseString)) { |
81 |
| - |
82 |
| - $this->deserializedResponse["ErrorNo"]= CENTINEL_ERROR_CODE_8020; |
83 |
| - $this->deserializedResponse["ErrorDesc"]= CENTINEL_ERROR_CODE_8020_DESC; |
84 |
| - } |
85 |
| - |
86 |
| - xml_parser_free($this->xml_parser); |
87 |
| - } |
88 |
| - } |
| 15 | +class XMLParser |
| 16 | +{ |
| 17 | + public $xml_parser; |
| 18 | + public $deseralizedResponse; |
| 19 | + public $elementName; |
| 20 | + public $elementValue; |
| 21 | + |
| 22 | + ///////////////////////////////////////////////////////////////////////////////////////////// |
| 23 | + // Function XMLParser() |
| 24 | + // |
| 25 | + // Initialize the XML parser. |
| 26 | + ///////////////////////////////////////////////////////////////////////////////////////////// |
| 27 | + |
| 28 | + public function __construct() |
| 29 | + { |
| 30 | + $this->xml_parser = xml_parser_create(); |
| 31 | + } |
| 32 | + |
| 33 | + ///////////////////////////////////////////////////////////////////////////////////////////// |
| 34 | + // Function startElement(parser, name, attribute) |
| 35 | + // |
| 36 | + // Start Tag Element Handler |
| 37 | + ///////////////////////////////////////////////////////////////////////////////////////////// |
| 38 | + |
| 39 | + public function startElement($parser, $name, $attrs='') |
| 40 | + { |
| 41 | + $this->elementName= $name; |
| 42 | + } |
| 43 | + |
| 44 | + ///////////////////////////////////////////////////////////////////////////////////////////// |
| 45 | + // Function elementData(parser, data) |
| 46 | + // |
| 47 | + // Element Data Handler |
| 48 | + ///////////////////////////////////////////////////////////////////////////////////////////// |
| 49 | + |
| 50 | + public function elementData($parser, $data) |
| 51 | + { |
| 52 | + $this->elementValue .= $data; |
| 53 | + } |
| 54 | + |
| 55 | + ///////////////////////////////////////////////////////////////////////////////////////////// |
| 56 | + // Function endElement(name, value) |
| 57 | + // |
| 58 | + // End Tag Element Handler |
| 59 | + ///////////////////////////////////////////////////////////////////////////////////////////// |
| 60 | + |
| 61 | + public function endElement($parser, $name) |
| 62 | + { |
| 63 | + $this->deserializedResponse[$this->elementName]= $this->elementValue; |
| 64 | + $this->elementName = ''; |
| 65 | + $this->elementValue = ''; |
| 66 | + } |
| 67 | + |
| 68 | + ///////////////////////////////////////////////////////////////////////////////////////////// |
| 69 | + // Function deserialize(xmlString) |
| 70 | + // |
| 71 | + // Deserilize the XML reponse message and add each element to the deseralizedResponse collection. |
| 72 | + // Once complete, then each element reference will be available using the getValue function. |
| 73 | + ///////////////////////////////////////////////////////////////////////////////////////////// |
| 74 | + |
| 75 | + public function deserializeXml($responseString) |
| 76 | + { |
| 77 | + xml_set_object($this->xml_parser, $this); |
| 78 | + xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, false); |
| 79 | + xml_set_element_handler($this->xml_parser, 'startElement', 'endElement'); |
| 80 | + xml_set_character_data_handler($this->xml_parser, 'elementData'); |
| 81 | + |
| 82 | + if (!xml_parse($this->xml_parser, $responseString)) { |
| 83 | + $this->deserializedResponse['ErrorNo']= CENTINEL_ERROR_CODE_8020; |
| 84 | + $this->deserializedResponse['ErrorDesc']= CENTINEL_ERROR_CODE_8020_DESC; |
| 85 | + } |
| 86 | + |
| 87 | + xml_parser_free($this->xml_parser); |
| 88 | + } |
| 89 | +} |
0 commit comments