dennismonsewicz Posted August 3, 2009 Share Posted August 3, 2009 Hello yall, I am a complete NEWB to simplexml, so, sorry for this post... here is my simplexml code to display content: $xml = simplexml_load_string($row->content); var_dump($xml); output to browser: object(SimpleXMLElement) (2) { ["@attributes"]=> array(2) { ["available-locales"]=> string(5) "en_US" ["default-locale"]=> string(5) "en_US" } ["static-content"]=> object(SimpleXMLElement) (2) { ["@attributes"]=> array(1) { ["language-id"]=> string(5) "en_US" } ["#cdata-section"]=> object(SimpleXMLElement) (0) { } } } how do I parse the above to display the static-content? Link to comment https://forums.phpfreaks.com/topic/168694-simplexml-help/ Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 could you post some XML for us. Parsing the output is kind of a headache. Link to comment https://forums.phpfreaks.com/topic/168694-simplexml-help/#findComment-889961 Share on other sites More sharing options...
dennismonsewicz Posted August 3, 2009 Author Share Posted August 3, 2009 here is the XML string that is coming back <?xml version='1.0' encoding='UTF-8'?><root available-locales="en_US" default-locale="en_US"><static-content language-id="en_US"><![CDATA[<div style="width: 800px;"><div style="float: left;"><img border="0" src="/image/image_gallery?uuid=1223947d-4f92-4531-b790-3cdfb0276b41&groupId=14&t=1243886532560" alt="" /></div> <div style="float: right;"><img border="0" src="/image/image_gallery?uuid=cdf5279a-8d6b-421e-9984-860b9f679632&groupId=14&t=1243886532561" alt="" /></div> <br /> <table width="100%" cellpadding="2" bordercolor="#a9a9a9" border="1"> <tbody> <tr> <td>For customers who enroll in the <strong>metroGuard</strong> program on or after November 1, 2004, the equipment deductible is based on your phone model per the schedule below:</td> </tr> </tbody> </table> <table border="0"> <tbody> <tr> <td> </td> </tr> </tbody> </table> <table width="100%" cellpadding="2" bordercolor="#a9a9a9" border="1"> <tbody> <tr bordercolor="#000000"> <th align="left">Program A</th> <th align="left">Program B</th> <th align="left">Program C</th> </tr> <tr bordercolor="#000000"> <th align="left">$50 Deductible</th> <th align="left">$85 Deductible</th> <th align="left">$35 Deductible</th> </tr> <tr> <td>Audiovox 8500, 8615</td> <td>Audiovox 8900, 8910, 8932</td> <td> </td> </tr> <tr> <td> </td> <td>Blackberry 8330</td> <td> </td> </tr> <tr> <td>Ericsson T206, T61C</td> <td> </td> <td> </td> </tr> <tr> <td>Huawei M328</td> <td> </td> <td>Huawei M318</td> </tr> <tr> <td>LG/LX 1200, 5400, 3200</td> <td> </td> <td> </td> </tr> <tr> <td>Kyocera K312, K312P, Rave(KX433C),<br /> KE433C, S14, S4000, 1155, 2235</td> <td>Kyocera Slider(SE47), K612(Strobe), E2000</td> <td>Kyocera Melo</td> </tr> <tr> <td>Nokia 2270, 2865, 3585, 3585i, 3586i,<br /> 3589i, 6015, 6015i, 2116i</td> <td>Nokia 3205, 6225, 6235, 6255, 6265, 8265i</td> <td>Nokia 1006, 1606, 2125i, 2135</td> </tr> <tr> <td>Motorola V262, VE240, W315, W385</td> <td>Motorola Hint, V266, V323i, KRZR <br /> K1m, RAZRV3, RAZR V3a, RAZRV3M, RAZRV3C, <br /> RAZRV3CMR,RAZRVCMS, RAZRV3S, K1M,<br /> SLVR L7C, Z6m</td> <td> </td> </tr> <tr> <td>Samsung N330, A570, A645, R300, R430</td> <td>Samsung A610, A670, A850, A870, Finesse, R400, <br /> R410, R450, U520</td> <td>Samsung R210 SPEX</td> </tr> <tr> <td>UTStarcom CDM 7025, 7126, 1450</td> <td>UTStarcom 8932</td> <td> </td> </tr> <tr> <td>ZTE C78, ZTEC79, ZTEC88</td> <td> </td> <td> </td> </tr> </tbody> </table> <table border="0"> <tbody> <tr> <td> </td> </tr> </tbody> </table> <table width="100%" cellpadding="2" bordercolor="#a9a9a9" border="1"> <tbody> <tr> <td bgcolor="#c0c0c0"><strong>metroGUARD</strong> is a service provided to subscribers of MetroPCS, administered by Asurion Insurance Services,Inc. and<br /> Old Republic Insurance Company</td> </tr> </tbody> </table></div>]]></static-content></root> Link to comment https://forums.phpfreaks.com/topic/168694-simplexml-help/#findComment-889963 Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 your xml didn't like being parsed. I had to change static-content to static_content and language-id to language_id to get this to work, but here's an example: <?php $data = "<?xml version='1.0' encoding='UTF-8'?> <root available-locales='en_US' default-locale='en_US'> <static_content language_id='en_US'> <![CDATA[<div style='width: 800px;'><div style='float: left;'><img border='0' src='/image/image_gallery?uuid=1223947d-4f92-4531-b790-3cdfb0276b41&groupId=14&t=1243886532560' alt='' /></div> <div style='float: right;'><img border='0' src='/image/image_gallery?uuid=cdf5279a-8d6b-421e-9984-860b9f679632&groupId=14&t=1243886532561' alt='' /></div> <br /> <table width='100%' cellpadding='2' bordercolor='#a9a9a9' border='1'> <tbody> <tr> <td>For customers who enroll in the <strong>metroGuard</strong> program on or after November 1, 2004, the equipment deductible is based on your phone model per the schedule below:</td> </tr> </tbody> </table> <table border='0'> <tbody> <tr> <td> </td> </tr> </tbody> </table> <table width='100%' cellpadding='2' bordercolor='#a9a9a9' border='1'> <tbody> <tr bordercolor='#000000'> <th align='left'>Program A</th> <th align='left'>Program B</th> <th align='left'>Program C</th> </tr> <tr bordercolor='#000000'> <th align='left'>$50 Deductible</th> <th align='left'>$85 Deductible</th> <th align='left'>$35 Deductible</th> </tr> <tr> <td>Audiovox 8500, 8615</td> <td>Audiovox 8900, 8910, 8932</td> <td> </td> </tr> <tr> <td> </td> <td>Blackberry 8330</td> <td> </td> </tr> <tr> <td>Ericsson T206, T61C</td> <td> </td> <td> </td> </tr> <tr> <td>Huawei M328</td> <td> </td> <td>Huawei M318</td> </tr> <tr> <td>LG/LX 1200, 5400, 3200</td> <td> </td> <td> </td> </tr> <tr> <td>Kyocera K312, K312P, Rave(KX433C),<br /> KE433C, S14, S4000, 1155, 2235</td> <td>Kyocera Slider(SE47), K612(Strobe), E2000</td> <td>Kyocera Melo</td> </tr> <tr> <td>Nokia 2270, 2865, 3585, 3585i, 3586i,<br /> 3589i, 6015, 6015i, 2116i</td> <td>Nokia 3205, 6225, 6235, 6255, 6265, 8265i</td> <td>Nokia 1006, 1606, 2125i, 2135</td> </tr> <tr> <td>Motorola V262, VE240, W315, W385</td> <td>Motorola Hint, V266, V323i, KRZR <br /> K1m, RAZRV3, RAZR V3a, RAZRV3M, RAZRV3C, <br /> RAZRV3CMR,RAZRVCMS, RAZRV3S, K1M,<br /> SLVR L7C, Z6m</td> <td> </td> </tr> <tr> <td>Samsung N330, A570, A645, R300, R430</td> <td>Samsung A610, A670, A850, A870, Finesse, R400, <br /> R410, R450, U520</td> <td>Samsung R210 SPEX</td> </tr> <tr> <td>UTStarcom CDM 7025, 7126, 1450</td> <td>UTStarcom 8932</td> <td> </td> </tr> <tr> <td>ZTE C78, ZTEC79, ZTEC88</td> <td> </td> <td> </td> </tr> </tbody> </table> <table border='0'> <tbody> <tr> <td> </td> </tr> </tbody> </table> <table width='100%' cellpadding='2' bordercolor='#a9a9a9' border='1'> <tbody> <tr> <td bgcolor='#c0c0c0'><strong>metroGUARD</strong> is a service provided to subscribers of MetroPCS, administered by Asurion Insurance Services,Inc. and<br /> Old Republic Insurance Company</td> </tr> </tbody> </table></div>]]> </static_content> </root>"; $xml = simplexml_load_string($data); $lang = (string)$xml->static_content->attributes()->language_id; print $lang; Link to comment https://forums.phpfreaks.com/topic/168694-simplexml-help/#findComment-889984 Share on other sites More sharing options...
dennismonsewicz Posted August 3, 2009 Author Share Posted August 3, 2009 hmmm thanks! The problem is that I am retrieving this from a database, how can I change that on the fly (the hypens to underscores)? Link to comment https://forums.phpfreaks.com/topic/168694-simplexml-help/#findComment-889992 Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 can't test it, but I think this will do it: <?php $content = str_replace("static-content", "static_content", $row->content); $content = str_replace("language-id", "language_id", $content); $xml = simplexml_load_string($content); var_dump($xml); Link to comment https://forums.phpfreaks.com/topic/168694-simplexml-help/#findComment-890005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.