The method of adding CDATA labels when php generates xml is very simple, because it is a tag that can store various content in xml. the following example is provided to help you. stick the code to keep scars, don't put it! [CDATA [$ text... the method of adding CDATA labels when php generates xml is very simple, because it is a tag that can store various content in xml. the following example is provided to help you.
Stick the code to keep scars. $textAs the prefix suffix, it can actually be a tag. the code is as follows:
createElement("toppings"); $dom->appendChild($root); // create child element $item = $dom->createElement("item"); $root->appendChild($item); // create text node $text = $dom->createTextNode("pepperoni"); $item->appendChild($text); // create attribute node $price = $dom->createAttribute("price"); $item->appendChild($price); // create attribute value node $priceValue = $dom->createTextNode("4"); $price->appendChild($priceValue); // create CDATA section $cdata = $dom->createCDATASection(" Customer requests that pizza be sliced into 16 square pieces "); $root->appendChild($cdata); // create PI $pi = $dom->createProcessingInstruction("pizza", "bake()"); $root->appendChild($pi); // save and display tree echo $dom->saveXML();
Address:
Reprinted at will, but please attach the article address :-)