Php generated xml document problem php generated xml, I found four methods on the Internet, but when I did the result, the process is as follows: the xml to be output is: & lt ;? Xml & nbsp; version = "1.0" & nbsp; encoding = "UTF-8 "? & Gt; & nbsp; & lt; xml document generated by artic php
Php generates xml. I searched the internet for four methods, but when I did it myself, the result was incorrect. The process is as follows:
The xml to be output is:
Title1
Content1
2009-10-
Title2
Content2
For example, if I use SimpleXML to create an XML document, the code is as follows (all are online examples ):
$ Data_array = array (
Array (
'Title' => 'title1 ',
'Content' => 'content1 ',
'Pubdate' => '2017-10-11 ',
),
Array (
'Title' => 'title2 ',
'Content' => 'content2 ',
'Pubdate' => '2017-11-11 ',
)
);
// Attribute array
$ Attribute_array = array (
'Title' => array (
'Size' => 1
)
);
$ String = <
XML;
$ Xml = simplexml_load_string ($ string );
Foreach ($ data_array as $ data ){
$ Item = $ xml-> addChild ('ITEM ');
If (is_array ($ data )){
Foreach ($ data as $ key => $ row ){
$ Node = $ item-> addChild ($ key, $ row );
If (isset ($ attribute_array [$ key]) & is_array ($ attribute_array [$ key])
{
Foreach ($ attribute_array [$ key] as $ akey => $ aval ){
// Set the attribute value
$ Node-> addAttribute ($ akey, $ aval );
}
}
}