simplexml


Copying CDATA between 2 xml files


I've been banging my head with that one, but it should be simple!
I'm trying to increment xml1 from values parsed in xml2. Working well for all nodes except that contains CDATA. I am copying according to this loop:
$xml1 = simplexml_load_file("history.kml");
$xml2 = simplexml_load_file("history_compare.kml");
foreach ($xml2->Document->Placemark as $Placemark){
$new_Placemark = $xml1->Document->addChild('Placemark');
$new_Placemark->addChild('name', $Placemark->name);
$new_Placemark->addChild('description', $Placemark->description);
$xml_history->asXML('xml_result.kml');
}
The <description> tag in xml2 contains CDATA.
When trying to copy this tag, the result completely escapes the description tag. Here is the output:
<Placemark>
<name>2016-12-29 10:45:39 AM</name>
<description/>
</Placemark>
I want the <description> tag to be copied as a CDATA, exactly the same as it is in source $xml2.
I've seen solutions to ignore CDATA but that is not what I'm looking for here.
Thanks

Related Links

Simplexml Insert into sub element
warning: simplexml_load_file(): I/O warning : failed to load external entity drupal [closed]
What's wrong with this code? SimpleXMLElement [closed]
Get children attributes using simplexml
Select attribute in simplexml
Save formatted xml
SimpleXML (Zend_Config_Xml actually) and foreach : which tag am I iterating?
simplexml_load_file() error happening in only localhost/xampp
SimpleXml tar.gz
simplexml_load_file error in PHP 5.3
simplexml_load_file not a valid URI issue
Can't turn XML response into an simplexml object
Having trouble getting Fogbugz API response into a SimpleXML object
Upgraded to php 5.3.10 and simpleXMLelement is broken
Parsing RSS Feed with SimpleXML
php simplexml_load_file (script url) failed to open stream

Categories

HOME
xamarin
deezer
tizen
hashmap
session
at-command
binary-tree
django-imagekit
n-gram
circuit
vaadin7
aurigma
openedx
nodatime
lldb
orleans
sqlcipher
numerical-methods
kannel
windows-error-reporting
jspm
vision
google-cloud-nl
skia
tinymce-4
directx-10
calibre
vsts-build-task
textmate
form-data
google-api-nodejs-client
mapdb
simplexml
swift3.0.2
reportbuilder
unobtrusive-validation
angularjs-factory
awt
password-encryption
filepicker
komodoedit
clean-architecture
nstextview
google-perftools
epson
sonarlint-vs
chord-diagram
eventkit
time-and-attendance
django-debug-toolbar
qpid
markojs
hover-over
dlna
bluegiga
php-parse-error
historian
icu4j
varargs
umbraco6
directoryservices
xc16
dd
issuu
aapt
jubula
seaside
multiprocessor
dexterity
sitemesh
bulkloader
back-stack
anonymous-methods
hamiltonian-cycle
libstdc++
isnullorempty
quickdialog
google-email-migration
first-responder
runas
enter
removeclass
hgsubversion
coercion
joyent
javax.script
calling-convention
zend-translate
suppress
icanhaz.js
getresponsestream
backcolor
virtual-functions
anti-piracy
procedural-music
scripting-languages

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App