Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.