Albert Renshaw Albert Renshaw - 1 year ago 54
PHP Question

Create XML via PHP & MySQL (for use by action script 2)

Possible Duplicate:

How to parse HTML with PHP?

Get MySQL database output via PHP to XML

I have some tables in MySQL.... Can I use PHP to create a .xml file on my website that will neatly contain the information from my MySQL database?

On a side note if I am retrieving xml information in action script 2.0 do I HAVE to retrieve it from a .xml file or can I have a .php file that creates an open and close tag on the page and then creates an xml table on the .php page?

Answer Source

you can create XML in PHP and you can save it as file or echo as XML string , you can use below sample codes

        $xml = new DOMDocument('1.0', 'iso-8859-1');

        $rootNode = $xml->createElement('xmlrootnode');
        $rootNode = $xml->appendChild($rootNode);

        foreach( $resultArr as $r )  {

            $sDateArr = explode( ' ', $r['start_time'] );
            $sRootN = $xml->createElement('date');
            $sRootN = $rootNode->appendChild($sRootN);
            $sRootN->setAttribute('value', $sDateArr[0]);

            //Id field
            $idN = $xml->createElement('id');
            $idN = $sRootN->appendChild($idN);

            $idT = $xml->createTextNode(htmlentities($r['id']));
        //header('Content-type: text/xml');
        //echo $xmlStr = $xml->saveXML();
        $xmlStr = isset($xml) ? htmlspecialchars($xml->saveXML()) : '';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download