-3

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?

1
  • Asked as a separate question because of the ActionScript 2 part... Commented Jan 18, 2012 at 22:21

2 Answers 2

1

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']));
            $idN->appendChild($idT);
        }
        //$xml->save($xml);
        //header('Content-type: text/xml');
        //echo $xmlStr = $xml->saveXML();
        $xmlStr = isset($xml) ? htmlspecialchars($xml->saveXML()) : '';
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! Thanks for the productive response!
1

As an answer to your side note:
Yes you can - thats the normal way to do it.
AS does not even know if it was a file or created on the fly - it just receives the data and if it is valid XML it should work...

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.