helraizer Posted November 29, 2007 Share Posted November 29, 2007 Hi folks, I'm only just learning XML (easier than I thought) but I have this layout for it. I have a form and php code to put the username, message etc.. into a database. The Layout of XML version is a lot better, though.. Would it be possible to add the username, title and message to the XML so it'd be like: <messages> <message> <from><?php echo $user; ?> </from> <!-- Since you can't add '<' character into the XML --> <title></title> <body></body> </message> </messages> <?xml version="1.0" encoding="ISO-8859-1"?> <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"> <body style="font-family:Arial,helvetica,sans-serif;font-size:12pt; background-color:#FFFFFF;"> <xsl:for-each select="messages/message"> <div style="background-color:#ececec;width:480px;padding:10px;"> <xsl:value-of select="body"/> </div> <div style="background: url(arrow.gif) 20px 0 no-repeat;padding-left:58px;paddingtop:1px;margin-bottom:2em;font-size:90%;color:#4A4A4A"> Title: <xsl:value-of select="title"/> <span style="font-style:italic"> (Posted by: <xsl:value-of select="from"/>) </span> </div> </xsl:for-each> </body> </html> Or whatever, so eachtime the username, title and message are added within those tags (new tags for each username/message)? Hope that's clear enough, holler if it isn't. Sam Quote Link to comment https://forums.phpfreaks.com/topic/79469-php-variables-to-xml/ Share on other sites More sharing options...
sKunKbad Posted November 29, 2007 Share Posted November 29, 2007 What version of php are you running? Quote Link to comment https://forums.phpfreaks.com/topic/79469-php-variables-to-xml/#findComment-402389 Share on other sites More sharing options...
helraizer Posted November 29, 2007 Author Share Posted November 29, 2007 What version of php are you running? php5 currently. I tried a few things with it but from what I'm aware if you use php in XML you have to save as .php and if you use XML in php for it to work, save it as XML which then the php wouldn't parse.. so is it possible? Quote Link to comment https://forums.phpfreaks.com/topic/79469-php-variables-to-xml/#findComment-402403 Share on other sites More sharing options...
sKunKbad Posted November 30, 2007 Share Posted November 30, 2007 The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators. See Example 8 on http://www.php.net/manual/en/ref.simplexml.php Example#8 Setting values Data in SimpleXML doesn't have to be constant. The object allows for manipulation of all of its elements. <?php include 'example.php'; $xml = new SimpleXMLElement($xmlstr); $xml->movie[0]->characters->character[0]->name = 'Miss Coder'; echo $xml->asXML(); ?> The above code will output a new XML document, just like the original, except that the new XML will change Ms. Coder to Miss Coder. Quote Link to comment https://forums.phpfreaks.com/topic/79469-php-variables-to-xml/#findComment-402697 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.