acondiff Posted July 12, 2010 Share Posted July 12, 2010 So I have an xml file that has a single node and I wanted to echo the node value. The XML looks like this: <node> <html> <![CDATA[ <p>This is my <b>HTML</b> text.</p> ]]> </html> </node> Ive tried the following but it does not work. $doc = new DOMDocument(); $doc->load( html.xml' ); $html_xml = $doc->getElementsByTagName( "html" ); $html_txt = $html_xml->nodeValue; echo $html_txt; How can I echo out this data? Thanks? Quote Link to comment https://forums.phpfreaks.com/topic/207478-echo-xml-data/ Share on other sites More sharing options...
bh Posted July 12, 2010 Share Posted July 12, 2010 Hi, Is there an error message cuz thats ok theres an error... anyway try sg like this: $html_txt = $html_xml->item(0)->nodeValue; Quote Link to comment https://forums.phpfreaks.com/topic/207478-echo-xml-data/#findComment-1084732 Share on other sites More sharing options...
acondiff Posted July 12, 2010 Author Share Posted July 12, 2010 ok a have it echoing in a textbox. now i need to have it save to the same xml file once the user makes the changes. I've got this: <?php if (array_key_exists('_submit_check', $_POST)) { $about = $_POST['about']; $xmlLoc = $_SERVER['DOCUMENT_ROOT'] . '/new/wp-content/themes/default/flash/xml/about.xml'; $doc = new DOMDocument(); $doc->formatOutput = true; $r = $doc->createElement( "html" ); $doc->appendChild( $r ); $a1 = appendChild($doc->createTextNode( $about ) ); $r->appendChild( $a1 ); $doc->save( $xmlLoc ); } ?> But it doesn't work. It gives me the following error: Fatal error: Call to undefined function appendChild() in /[serverpath]/functions.php on line 846 ($a1 = app...) I need it saving in this format: <node> <html> [node value goes here] </html> </node> Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/207478-echo-xml-data/#findComment-1084738 Share on other sites More sharing options...
bh Posted July 12, 2010 Share Posted July 12, 2010 $a1 = appendChild($doc->createTextNode( $about ) ); $r->appendChild( $a1 ); -> $a1 = $doc->createTextNode( $about ); $r->appendChild( $a1 ); Quote Link to comment https://forums.phpfreaks.com/topic/207478-echo-xml-data/#findComment-1084742 Share on other sites More sharing options...
acondiff Posted July 12, 2010 Author Share Posted July 12, 2010 It's giving me "<" instead of "<". And its not wrapping it all in CDATA. How can I do that? Quote Link to comment https://forums.phpfreaks.com/topic/207478-echo-xml-data/#findComment-1084746 Share on other sites More sharing options...
bh Posted July 12, 2010 Share Posted July 12, 2010 from google! // create CDATA section $cdata = $dom->createCDATASection("\nCustomer requests that pizza be sliced into 16 square pieces\n"); $root->appendChild($cdata); Quote Link to comment https://forums.phpfreaks.com/topic/207478-echo-xml-data/#findComment-1084750 Share on other sites More sharing options...
acondiff Posted July 12, 2010 Author Share Posted July 12, 2010 im sorry i have it wrong... $about = $_POST['about']; $xmlLoc = $_SERVER['DOCUMENT_ROOT'] . '/new/wp-content/themes/default/flash/xml/about.xml'; $doc = new DOMDocument(); $doc->formatOutput = true; $r = $doc->createElement( "html" ); $doc->appendChild( $r ); $a1 = $doc->createTextNode( $about ); $cdata = $dom->createCDATASection( $about ); $r->appendChild($cdata); $doc->save( $xmlLoc ); Fatal error: Call to a member function createCDATASection() on a non-object Quote Link to comment https://forums.phpfreaks.com/topic/207478-echo-xml-data/#findComment-1084751 Share on other sites More sharing options...
bh Posted July 12, 2010 Share Posted July 12, 2010 Yeah... (it was only an example, i dont specify for your script) $cdata = $dom->createCDATASection( $about ); $cdata = $doc->createCDATASection( $about ); Quote Link to comment https://forums.phpfreaks.com/topic/207478-echo-xml-data/#findComment-1084753 Share on other sites More sharing options...
acondiff Posted July 12, 2010 Author Share Posted July 12, 2010 thank you so much for your help. its working great now. =) Quote Link to comment https://forums.phpfreaks.com/topic/207478-echo-xml-data/#findComment-1085009 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.