1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
xmlcreator.php
См. документацию.
1<?php
2
4
5 var $tag;
6 var $data;
7 var $startCDATA = "";
8 var $endCDATA = "";
9
12
13 public function __construct($tag, $cdata = false)
14 {
15 $cdata ? $this->setCDATA() : null;
16 $this->tag = $tag;
17 }
18
19 // format of $heavyTag = '[Index:]TagName [asd:qwe="asd"] [zxc:dfg="111"]'
20 // returns created CXMLCreator node with setted TagName and Attributes
21 public static function createTagAttributed($heavyTag, $value = null)
22 {
23 $heavyTag = trim($heavyTag);
24 $name = $heavyTag;
25
26 $attrs = 0;
27 $attrsPos = mb_strpos($heavyTag, " ");
28
29 if ($attrsPos)
30 {
31 $name = mb_substr($heavyTag, 0, $attrsPos);
32 $attrs = mb_strstr(trim($heavyTag), " ");
33 }
34
35 if (!trim($name)) return false;
36
37 $nameSplited = explode(":", $name);
38 if ($nameSplited)
39 $name = $nameSplited[count($nameSplited) - 1];
41
42 $node = new CXMLCreator( $name );
43
44 if ($attrs and mb_strlen($attrs))
45 {
46 $attrsSplit = explode("\"", $attrs);
47 $i = 0;
48 while ($validi = mb_strpos(trim($attrsSplit[$i]), "="))
49 {
50 $attrsSplit[$i] = trim($attrsSplit[$i]);
51 // attr:ns=
52 $attrName = CDataXML::xmlspecialcharsback(mb_substr($attrsSplit[$i], 0, $validi));
53 // attrs:ns
54 $attrValue = CDataXML::xmlspecialcharsback($attrsSplit[$i+1]);
55
56 $node->setAttribute($attrName, $attrValue);
57 $i = $i + 2;
58 }
59 }
60
61 if (null !== $value)
62 $node->setData($value);
63
64 return $node;
65 }
66
67 public static function encodeValueLight( $name, $value)
68 {
69 global $xsd_simple_type;
70
71 //AddMessage2Log($name."|".mydump($value));
72 if (!$name)
73 {
74 ShowError("Tag name undefined (== 0) in encodeValueLight.");
75 return false;
76 }
77
79 $name = $node->tag;
80
81 if (!$node)
82 {
83 ShowError("Can't create NODE object. Unable to parse tag name: ".$name);
84 return false;
85 }
86
87 if (is_object($value) && mb_strtolower(get_class($value)) == "cxmlcreator")
88 {
89 $node->addChild($value);
90 }
91 else if (is_object($value))
92 {
93 $ovars = get_object_vars($value);
94 foreach ($ovars as $pn => $pv)
95 {
96 $decode = CXMLCreator::encodeValueLight( $pn, $pv);
97 if ($decode) $node->addChild($decode);
98 }
99 }
100 else if (is_array($value))
101 {
102 foreach ($value as $pn => $pv)
103 {
104 $decode = CXMLCreator::encodeValueLight( $pn, $pv);
105 if ($decode)
106 {
107 $node->addChild($decode);
108 }
109 }
110 }
111 else
112 {
113 if (!$value) $node->setData("");
114 else if (!isset($xsd_simple_type[gettype($value)]))
115 {
116 ShowError("Unknown param type.");
117 return false;
118 }
119
120 $node->setData($value);
121 }
122
123 return $node;
124 }
125
126 function setCDATA()
127 {
128 $this->startCDATA = "<![CDATA[";
129 $this->endCDATA = "]]>";
130 }
131
132 function setAttribute($attrName, $attrValue)
133 {
134 $newAttribute = array($attrName => $attrValue);
135 $this->attributs = array_merge($this->attributs, $newAttribute);
136 }
137
138 function setData($data)
139 {
140 $this->data = $data;
141 }
142
143 function setName($tag)
144 {
145 //$tag = static::xmlspecialchars($tag);
146 $this->tag = $tag;
147 }
148
149 function addChild($element)
150 {
151 //AddMessage2Log(mydump(get_class($element)));
152 if($element && (get_class($element) == "CXMLCreator" || get_class($element) == "cxmlcreator"))
153 {
154 array_push($this->children, $element);
155 }
156 }
157
159 {
160 return count($this->children);
161 }
162
163 function _getAttributs()
164 {
165 $attributs = "";
166 if (is_array($this->attributs)){
167 foreach($this->attributs as $key=>$val)
168 {
169 $attributs .= " " . static::xmlspecialchars($key). "=\"" . static::xmlspecialchars($val) . "\"";
170 }
171 }
172 return $attributs;
173 }
174
175 function _getChildren()
176 {
177 $children = "";
178 foreach($this->children as $key=>$val)
179 {
180 $children .= $val->getXML();
181 }
182 return $children;
183
184 }
185
186 function getXML()
187 {
188 if (!$this->tag) return "";
189 $xml = "<" . static::xmlspecialchars($this->tag) . $this->_getAttributs() . ">";
190 $xml .= $this->startCDATA;
191 $xml .= $this->data;
192 $xml .= $this->endCDATA;
193 $xml .= $this->_getChildren();
194 $xml .= "</" . static::xmlspecialchars($this->tag) . ">";
195 return $xml;
196 }
197
198 public static function getXMLHeader()
199 {
200 return "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
201 }
202
203 function __destruct()
204 {
205 unset($this->tag);
206 }
207
208 public static function CreateFromDOM($dom)
209 {
210 return CXMLCreator::__createFromDOM($dom->root[0]);
211 }
212
213 public static function __createFromDOM($domNode)
214 {
215 $result = new CXMLCreator($domNode->name);
216
217 $result->setData($domNode->content);
218
219 if (is_array($domNode->attributes))
220 {
221 foreach ($domNode->attributes as $attrDomNode)
222 {
223 $result->setAttribute($attrDomNode->name, $attrDomNode->content);
224 }
225 }
226
227 if (is_array($domNode->children))
228 {
229 foreach ($domNode->children as $domChild)
230 {
231 $result->addChild(CXMLCreator::__createFromDOM($domChild));
232 }
233 }
234
235 return $result;
236 }
237
238 public static function xmlspecialchars($str)
239 {
240 static $search = array("&","<",">","\"","'","\r","\n");
241 static $replace = array("&amp;","&lt;","&gt;","&quot;","&apos;","&#13;","&#10;");
242 return str_replace($search, $replace, $str);
243 }
244
245 public static function xmlspecialcharsback($str)
246 {
247 static $search = array("&lt;","&gt;","&quot;","&apos;","&amp;","&#13;","&#10;");
248 static $replace = array("<",">","\"","'","&","\r","\n");
249 return str_replace($search, $replace, $str);
250 }
251}
static xmlspecialcharsback($str)
Определения xml.php:518
Определения xmlcreator.php:3
setCDATA()
Определения xmlcreator.php:126
static getXMLHeader()
Определения xmlcreator.php:198
setName($tag)
Определения xmlcreator.php:143
addChild($element)
Определения xmlcreator.php:149
static __createFromDOM($domNode)
Определения xmlcreator.php:213
__destruct()
Определения xmlcreator.php:203
static CreateFromDOM($dom)
Определения xmlcreator.php:208
static xmlspecialcharsback($str)
Определения xmlcreator.php:245
setData($data)
Определения xmlcreator.php:138
static encodeValueLight( $name, $value)
Определения xmlcreator.php:67
$data
Определения xmlcreator.php:6
setAttribute($attrName, $attrValue)
Определения xmlcreator.php:132
$tag
Определения xmlcreator.php:5
__construct($tag, $cdata=false)
Определения xmlcreator.php:13
getChildrenCount()
Определения xmlcreator.php:158
$startCDATA
Определения xmlcreator.php:7
$children
Определения xmlcreator.php:11
$endCDATA
Определения xmlcreator.php:8
_getAttributs()
Определения xmlcreator.php:163
_getChildren()
Определения xmlcreator.php:175
$attributs
Определения xmlcreator.php:10
static createTagAttributed($heavyTag, $value=null)
Определения xmlcreator.php:21
getXML()
Определения xmlcreator.php:186
static xmlspecialchars($str)
Определения xmlcreator.php:238
$str
Определения commerceml2.php:63
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
ShowError($strError, $cls="errortext")
Определения tools.php:4499
$name
Определения menu_edit.php:35
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$val
Определения options.php:1793