Jump to content

fatal error with createTextNode()


sky

Recommended Posts

hello again,

I'm getting this output:
Fatal error: Call to a member function createTextNode() on a non-object

from this line:
$name= $tnode->createTextNode("michelle");

I get the same error when I try this as well:
$tnode->createTextNode("michelle");

can somebody tell me why?
Link to comment
Share on other sites

I used it like this:

<?php
$dom = new DomDocument;
$dom->formatoutput=true;
$dom->whiteSpace=true;
$dom->load("theXML.xml");


$element= $dom->createElement('name');
$dom->appendChild($element);


######## Try One###############
$element=$tnode->createTextNode("michelle");

########Try Two###############
//$tnode->createTextNode("michelle");

//$element->appendChild($tnode);



$dom->save("theXML.xml");
// saves the domDocument

?>


Is there a place to look up fatal errors and other errors
for php almost like a list of errors and possible reasons why?
Link to comment
Share on other sites

ok... think I got it.

Please tell me if I'm wrong you need to create everything at the $dom level first

[code]$element = $dom->createElement('saying');
$saying = $dom->createTextNode("hello");[/code]

THEN APPEND IT

[code]$element->appendChild($saying);
$dom->appendChild($element);[/code]
this is the standard way correct? Sorry just new to this.

Still curious about a list of errors and possible troubleshooting answers. Is there one available? I haven't found one I and google and search forum posts but nothing.
Link to comment
Share on other sites

I've been searching with google and looking in the two books I have "PHP 5-Power Programming" and "PHP, MySqL and Apache" and can not find something like you are talking about.

Are you saying I need to declare the variable type as in

$tnode= new [i]datatype[/i] ?

I see you do this in a class.
Should I do this with every variable? Declare it?

can you show me a line of how to do this?
Link to comment
Share on other sites

I want ---$tnode to be a text node--- that is appended to my $nameNode node
that is then appended to my $rootNode and then ultimate saved in my $dom and
saved to my xml file.

Here is what I'm working with.
It seems to work but I want to make sure it's the correct way to code.
What would be the correct way to create the object?

[code]<?php
$dom = new DomDocument;
$dom->load("theXML.xml");

$rootElement=$dom->createElement('person');
$nameNode=$dom->createElement('name');
$textNode=$dom->createTextNode("Thomas");

// Above I created my nodes to be appended
// to my $dom object and then saved in my file.

$nameNode->appendChild($textNode);
$rootElement->appendChild($nameNode);
$dom->appendChild($rootElement);

// appends all the nodes to the $dom object

$dom->save("newxmlfile.xml");
// saves the domDocument into a file called "theXML2.xml"

?>[/code]

output:
[code]<?xml version="1.0" encoding="iso-8859-1"?>
<person><name>Thomas</name></person>[/code]

thanks,

sky
Link to comment
Share on other sites

I'm sorry.

All I was trying to do was create an $dom object to append my xml file

I wanted to create a new element "$rootNode"
<person>    </person>

then create a text node for that element "$textNode"
  <person>
        <name> Thomas </name>
  </person>

should I just create another element and append
to the <person> element?

Did I create the $rootNode correctly?
Link to comment
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.