yanjchan Posted September 14, 2009 Share Posted September 14, 2009 Sorry for this short intro, but I'm a bit short on time. I keep getting an error whenever I try this; can someone please help me? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $answers = array( array( //2+2 is what!!! 'isdisputed' => 'yes', 'answers' => array( '1' => array( 'propnum' => '4', 'grades' => '84,98,42,67', 'answer' => '5' ) '2' => array( 'propnum' => '10', 'grades' => '100,98,99,86,86,20,86,100,100,100', 'answer' => '4' ) ) ) $xw = new xmlWriter(); $xw->openMemory(); //use openUri() to output directly to a file $xw->startDocument('1.0', 'UTF-8'); $xw->startElement('share'); $xw->writeElement('page', 'page#'); $xw->writeElement('numsequence', 'numseq'); $xw->writeElement('publisher', 'pub'); $xw->writeElement('book', 'bookname'); foreach ($answers as $answer) { $xw->startElement('answer'); // $xw->writeElement('answernumber', $answer); $xw->writeElement('isdisputed', $answer['isdisputed']); foreach ($answers['answers'] as $disputedanswer) { $xw->startElement('disputedanswer'); $xw->writeElement('supporters', $disputedanswer['propnum']); $xw->writeElement('grades', $disputedanswer['grades']); $xw->writeElement('answer', $disputedanswer['answer']); $xw->endElement(); } } $xw->endElement(); //item echo $xw; ?> </body> </html> Thanks in advance Quote Link to comment Share on other sites More sharing options...
AviNahum Posted September 14, 2009 Share Posted September 14, 2009 what error you got? Quote Link to comment Share on other sites More sharing options...
yanjchan Posted September 14, 2009 Author Share Posted September 14, 2009 Thanks for the quick reply; I get something along the lines of: Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /home/s2zsl9rx/public_html/share/xmlex.php on line 20 Quote Link to comment Share on other sites More sharing options...
AviNahum Posted September 14, 2009 Share Posted September 14, 2009 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $answers = array( array( //2+2 is what!!! 'isdisputed' => 'yes', 'answers' => array( '1' => array( 'propnum' => '4', 'grades' => '84,98,42,67', 'answer' => '5' ), '2' => array( 'propnum' => '10', 'grades' => '100,98,99,86,86,20,86,100,100,100', 'answer' => '4' ) ) ) ); $xw = new xmlWriter(); $xw->openMemory(); //use openUri() to output directly to a file $xw->startDocument('1.0', 'UTF-8'); $xw->startElement('share'); $xw->writeElement('page', 'page#'); $xw->writeElement('numsequence', 'numseq'); $xw->writeElement('publisher', 'pub'); $xw->writeElement('book', 'bookname'); foreach ($answers as $answer) { $xw->startElement('answer'); // $xw->writeElement('answernumber', $answer); $xw->writeElement('isdisputed', $answer['isdisputed']); foreach ($answers['answers'] as $disputedanswer) { $xw->startElement('disputedanswer'); $xw->writeElement('supporters', $disputedanswer['propnum']); $xw->writeElement('grades', $disputedanswer['grades']); $xw->writeElement('answer', $disputedanswer['answer']); $xw->endElement(); } } $xw->endElement(); //item echo $xw; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
yanjchan Posted September 14, 2009 Author Share Posted September 14, 2009 You don't know how monumentally thankful I am. Thank you, thank you, thank you, thank you! Thank you! Thank you, Thank you! A side question that I hope you won't mind: Is it possible to get XMLWriter to output in a human-reading-friendly format? Thanks!!! Quote Link to comment Share on other sites More sharing options...
AviNahum Posted September 14, 2009 Share Posted September 14, 2009 sorry, i dont really know how to work with XML... Quote Link to comment 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.