Php generates xml and converts [source code]. Php generates xml like a tree. you can add nodes one by one. you can add multiple subnodes under a parent node, functionmadexml () {get template information $ strTempInfo $ this-modelCmsObj-g php generates xml like a tree. add nodes one by one. you can add multiple subnodes under a parent node, function madexml ()
- {
- // Obtain template information
- $ StrTempInfo = $ this-> modelCmsObj-> getTemplate (2007 );
- $ ArrTemp = explode ("#", $ strTempInfo );
- Array_shift ($ arrTemp );
- $ ArrContents = array ();
- Foreach ($ arrTemp as $ k => $ v)
- {
- $ ArrContents [$ k] = explode (",", $ v );
- }
- // Parse it into an xml file
- $ ObjDom = new DOMDocument ("1.0 ");
- Header ("Content-Type: text/plain ");
- // Add element and text node
- $ Root = $ objDom-> createElement ("recommend ");
- $ ObjDom-> appendChild ($ root );
- Foreach ($ arrContents as $ k => $ v)
- {
- $ Item = $ objDom-> createElement ("entry ");
- $ Root-> appendChild ($ item );
- $ Nextitem1 = $ objDom-> createElement ("simgurl ");
- $ Nextitem2 = $ objDom-> createElement ("imgurl ");
- $ Nextitem3 = $ objDom-> createElement ("fileurl ");
- $ Item-> appendChild ($ nextitem1 );
- $ Item-> appendChild ($ nextitem2 );
- $ Item-> appendChild ($ nextitem3 );
- $ Text1 = $ objDom-> createTextNode ($ v [0]);
- $ Text = $ objDom-> createTextNode ($ v [1]);
- $ Text2 = $ objDom-> createTextNode ($ v [2]);
- $ Nextitem2-> appendChild ($ text1 );
- $ Nextitem3-> appendChild ($ text2 );
- $ Nextitem1-> appendChild ($ text );
- }
-
- Echo $ objDom-> saveXML ();
- }
Simplexml_load_string converts an xml string to a string
-
- $ String = <
-
-
- Forty What?
- Joe
- Jane
-
- I know thats the answer -- but whats the question?
-
-
- XML;
-
- $ Xml = simplexml_load_string ($ string );
-
- Var_dump ($ xml );
- ?>
-
-
- This script will display:
Templates, function madexml () {// Obtain template information $ strTempInfo = $ this-modelCmsObj-g...