@@ -39,7 +39,7 @@ class XmlElement{
39
39
*
40
40
* @param string|\SimpleXMLElement $xml_string
41
41
* @throws \Exception if SimpleXML is not loaded
42
- * @return XmlElement
42
+ * @return \Altumo\Xml\ XmlElement
43
43
*/
44
44
public function __construct ( $ xml_string = null ){
45
45
@@ -159,6 +159,7 @@ public function queryWithXpath( $xpath_query, $return_type = self::RETURN_TYPE_S
159
159
* @param string $filename
160
160
* @throws \Exception if file does not exist
161
161
* @throws \Exception if contents are not valid XML
162
+ * @return \Altumo\Xml\XmlElement
162
163
*/
163
164
public function loadFromFile ( $ filename ){
164
165
@@ -169,6 +170,8 @@ public function loadFromFile( $filename ){
169
170
$ contents = file_get_contents ($ filename );
170
171
$ this ->setContentsByString ($ contents );
171
172
173
+ return $ this ;
174
+
172
175
}
173
176
174
177
@@ -177,6 +180,7 @@ public function loadFromFile( $filename ){
177
180
*
178
181
* @param string $xml_string
179
182
* @throws \Exception on parse error
183
+ * @return \Altumo\Xml\XmlElement
180
184
*/
181
185
public function setContentsByString ( $ xml_contents ){
182
186
@@ -203,6 +207,8 @@ public function setContentsByString( $xml_contents ){
203
207
if ( !$ this ->isValid () ){
204
208
throw new \Exception ('XML Failed to parse. ' );
205
209
}
210
+
211
+ return $ this ;
206
212
207
213
}
208
214
@@ -211,6 +217,7 @@ public function setContentsByString( $xml_contents ){
211
217
* Creates a XmlElement
212
218
*
213
219
* @param string $xml_string
220
+ * @return \Altumo\Xml\XmlElement
214
221
*/
215
222
public function setContentsBySimpleXMLElement ( $ xml_contents ){
216
223
@@ -221,7 +228,8 @@ public function setContentsBySimpleXMLElement( $xml_contents ){
221
228
222
229
$ this ->xml_element = $ xml_contents ;
223
230
$ this ->setLoaded (true );
224
- $ this ->setValid (true );
231
+ $ this ->setValid (true );
232
+ return $ this ;
225
233
226
234
}
227
235
@@ -384,7 +392,7 @@ public function getXmlAsString( $pretty = false, $include_xml_declaration = true
384
392
* @param string $name
385
393
* @param string $value
386
394
* @param string $namespace
387
- * @return XmlElement
395
+ * @return \Altumo\Xml\ XmlElement
388
396
*/
389
397
public function addAttribute ( $ name , $ value , $ namespace = null ){
390
398
@@ -401,17 +409,62 @@ public function addAttribute( $name, $value, $namespace = null ){
401
409
* @param string $name
402
410
* @param string $value
403
411
* @param string $namespace
404
- * @return XmlElement
412
+ * @return \Altumo\Xml\ XmlElement
405
413
*/
406
414
public function addChild ( $ name , $ value = null , $ namespace = null ){
407
415
408
416
$ this ->assertLoaded ();
417
+ /*
418
+ if( is_string($value) ){
419
+ //$value = str_replace( ' ', ' ', $value );
420
+ //$value = htmlentities( $value , ENT_COMPAT | ENT_HTML401 );
421
+ }*/
409
422
$ child = $ this ->getXmlElement ()->addChild ( $ name , $ value , $ namespace );
423
+
410
424
return new XmlElement ($ child );
411
425
412
426
}
413
427
414
428
429
+ /**
430
+ * Add CDATA text in a node
431
+ * @param string $cdata_text The CDATA value to add
432
+ *
433
+ * @author Alexandre FERAUD
434
+ * @see http://www.php.net/manual/en/simplexmlelement.addchild.php
435
+ */
436
+ protected function addCdata ( $ cdata_text ){
437
+
438
+ $ node = dom_import_simplexml ( $ this ->getXmlElement () );
439
+ $ owner_document = $ node ->ownerDocument ;
440
+ $ node ->appendChild ( $ owner_document ->createCDATASection ($ cdata_text ) );
441
+
442
+ }
443
+
444
+
445
+ /**
446
+ * Create a child element with CDATA value.
447
+ *
448
+ * @param string $name
449
+ * //The name of the child element to add.
450
+ *
451
+ * @param string $cdata_text
452
+ * //The CDATA value of the child element.
453
+ *
454
+ * @author Alexandre FERAUD
455
+ * @see http://www.php.net/manual/en/simplexmlelement.addchild.php
456
+ *
457
+ * @return \Altumo\Xml\XmlElement
458
+ */
459
+ public function addChildCdata ( $ name , $ cdata_text , $ namespace = null ){
460
+
461
+ $ child = $ this ->addChild ( $ name , null , $ namespace );
462
+ $ child ->addCdata ( $ cdata_text );
463
+ return $ this ;
464
+
465
+ }
466
+
467
+
415
468
/**
416
469
* Formats the xml string provided as a pretty output.
417
470
*
0 commit comments