Jump to content

Echo XML Data


acondiff

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/207478-echo-xml-data/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/207478-echo-xml-data/#findComment-1084738
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/207478-echo-xml-data/#findComment-1084751
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.