Nazirul Posted April 19, 2009 Share Posted April 19, 2009 Hi... i want to declare XML in PHP just like ASP code below : <!--#include file="ADOVBS.INC"--> <% Set ConnObj = Server.CreateObject("ADODB.Connection") Set RstObj = Server.CreateObject("ADODB.Recordset") ConnObj.Open "spa" sql="select *from CUSTOMER" set RstObj=ConnObj.Execute(sql,RecordsAffected) %> <?xml version="1.0" encoding="windows-1252"?> <?xml-stylesheet type="text/xsl" href="ViewAllSpaCust.xsl"?> <Senarai_Pelanggan> <% While not rstobj.eof %> <senarai> </senarai><senarai><Nama><%=rstobj("CUSTNAME")%></Nama> <NoIc><%=rstobj("CUSTIC")%></NoIc> <Gender><%=rstobj("CUSTGENDER")%></Gender> <Address><%=rstobj("CUSTADDRESS")%> </Address> <Race><%=rstobj("CUSTRACE")%></Race> <Dob><%=rstobj("CUSTDOB")%></Dob> <MobileNo><%=rstobj("CUSTMOBILENO")%></MobileNo> <HomeNo><%=rstobj("CUSTHOMENO")%></HomeNo> <MemberDate><%=rstobj("CUSTMEMBERDATE")%></MemberDate> </senarai> <%rstobj.MoveNext%> <%wend%> </Senarai_Pelanggan> what is the similar syntax for the XML embedded in PHP just like the ASP.. i've tried : <?php //php code goes here ?> <?xml version="1.0" encoding="ISO-8859-1"?> .. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>... but no luck.. it give error : Parse error: syntax error, unexpected T_STRING in C:\wamp\www\collegeXML\ViewStudent.php on line 28 hmm.. Quote Link to comment https://forums.phpfreaks.com/topic/154757-solved-convert-asp-coding-to-php/ Share on other sites More sharing options...
DarkSuperHero Posted April 19, 2009 Share Posted April 19, 2009 well whats the php code inside your php tags? Cant tell u what the error is without anycode to look at... and you more likley would have something along these lines... <?php //php code goes here to query DB ?> <?xml version="1.0" encoding="windows-1252"?> <?xml-stylesheet type="text/xsl" href="ViewAllSpaCust.xsl"?> <Senarai_Pelanggan> <?php //your php goes here....just echo/print any xml eg... echo '<tag>'. $phpVariableHoldingValue .'</tag>'; ?> </Senarai_Pelanggan> or you can also look into php5's XMLWriter class... Quote Link to comment https://forums.phpfreaks.com/topic/154757-solved-convert-asp-coding-to-php/#findComment-813822 Share on other sites More sharing options...
Nazirul Posted April 19, 2009 Author Share Posted April 19, 2009 well... the error was in line 28 .. that refer to the <?xml version="1.0" encoding="windows-1252"?> im not sure if it either php version problem...im using php 4.4.8 right now.. i've tried this <studNumber><? $Student_Number ?></studNumber> but no luck... Quote Link to comment https://forums.phpfreaks.com/topic/154757-solved-convert-asp-coding-to-php/#findComment-813831 Share on other sites More sharing options...
DarkSuperHero Posted April 19, 2009 Share Posted April 19, 2009 ah...yes....i've come accross that before my work around for that was just to echo the xml declaration... <?php echo '<?xml version="1.0" encoding="windows-1252"?>'; ?> Its the only way I was able to do it, php interpreter might confuse the <?xml for a short php tag..... Quote Link to comment https://forums.phpfreaks.com/topic/154757-solved-convert-asp-coding-to-php/#findComment-813846 Share on other sites More sharing options...
Nazirul Posted April 19, 2009 Author Share Posted April 19, 2009 lol.. use ----> php 5 <?php echo '<?xml version="1.0" encoding="ISO-8859-1"?>'; echo '<?xml-stylesheet type="text/xsl" href="ViewStudent2.xsl"?>'; echo '<student>'; echo '<room_number>'. $room_number .'</room_number>'; echo '<student_number>'. $student_number .'</student_number>'; echo '<student_name>'. $student_name .'</student_name>'; echo '<student_course>'. $student_course .'</student_course>'; echo '<semester>'. $semester .'</semester>'; echo '<address>'. $address .'</address>'; echo '<under>'. $Undergraduate_From .'</under>'; echo '</student>'; ?> that works... but the XSL cant be used .. echo '<?xml-stylesheet type="text/xsl" href="ViewStudent2.xsl"?>'; Quote Link to comment https://forums.phpfreaks.com/topic/154757-solved-convert-asp-coding-to-php/#findComment-813876 Share on other sites More sharing options...
DarkSuperHero Posted April 19, 2009 Share Posted April 19, 2009 how about sending some headers specifying that its an XML document...then maybe your document be rendered correctly... <?php header('Content-type:text/xml'); echo '<?xml version="1.0" encoding="ISO-8859-1"?>'; //after echo and before <? theres a ' echo '<?xml-stylesheet type="text/xsl" href="ViewStudent2.xsl"?>'; echo '<student>'; echo '<room_number>'. $room_number .'</room_number>'; echo '<student_number>'. $student_number .'</student_number>'; echo '<student_name>'. $student_name .'</student_name>'; echo '<student_course>'. $student_course .'</student_course>'; echo '<semester>'. $semester .'</semester>'; echo '<address>'. $address .'</address>'; echo '<under>'. $Undergraduate_From .'</under>'; echo '</student>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/154757-solved-convert-asp-coding-to-php/#findComment-813903 Share on other sites More sharing options...
Nazirul Posted April 19, 2009 Author Share Posted April 19, 2009 not work.. i think the reason why it works might be.. the php ignore the '<room_number' n etc... and only display the $value my friend email me the working code and it is : <?php ob_start(); session_start(); ?> <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="detail.xsl"?> <!DOCTYPE recipe SYSTEM "detail.dtd"> <recipe> <?php $id = $_GET['id']; include("library/config.php"); include("library/opendb.php"); $sql = "SELECT * FROM recipe WHERE id = '$id' AND act = '0'"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $cat_id = $row['category']; $sql = "SELECT cat_name FROM category WHERE id = '$cat_id'"; $result2 = mysql_query($sql); $r = mysql_fetch_array($result2); ?> <data> <recId><?php echo $id; ?></recId> <recTitle><?php echo $row['title']; ?></recTitle> <ingredient><?php echo $row['ingredient']; ?></ingredient> <instruction><?php echo $row['instruction']; ?></instruction> <suggestion><?php echo $row['suggestion']; ?></suggestion> <comment><?php echo $row['comment']; ?></comment> <source><?php echo $row['source']; ?></source> <sender><?php echo $row['name']; ?></sender> <email><?php echo $row['email']; ?></email> <date><?php echo $row['date']; ?></date> <catId><?php echo $cat_id; ?></catId> <catName><?php echo $r['cat_name']; ?></catName> </data> <formFunction> <approve><a href='approve.php' class='content'>Approve</a></approve> </formFunction> <?php include("library/closedb.php"); ?></recipe> great thanks : DarkSuperHero you are very helpful... Quote Link to comment https://forums.phpfreaks.com/topic/154757-solved-convert-asp-coding-to-php/#findComment-813940 Share on other sites More sharing options...
DarkSuperHero Posted April 19, 2009 Share Posted April 19, 2009 Cheers! Thank for posting your resolution code! I'm actually going to start working on a script that generates some XML for one of my next projects... Quote Link to comment https://forums.phpfreaks.com/topic/154757-solved-convert-asp-coding-to-php/#findComment-813970 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.