sky Posted January 27, 2007 Share Posted January 27, 2007 hello again,I'm getting this output:Fatal error: Call to a member function createTextNode() on a non-objectfrom 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? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 27, 2007 Share Posted January 27, 2007 Where did you create $tnode? Quote Link to comment Share on other sites More sharing options...
sky Posted January 27, 2007 Author Share Posted January 27, 2007 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 errorsfor php almost like a list of errors and possible reasons why? Quote Link to comment Share on other sites More sharing options...
sky Posted January 27, 2007 Author Share Posted January 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 27, 2007 Share Posted January 27, 2007 you never initialize $tnode.At some point you need to do $tnode = new (whatever the heck this object type is); Quote Link to comment Share on other sites More sharing options...
sky Posted January 27, 2007 Author Share Posted January 27, 2007 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? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 27, 2007 Share Posted January 27, 2007 You can't use the -> operator on a non-object. What is $tnode supposed to be? A "Text Node". What is that?$element=$tnode->createTextNode("michelle");Where is the function createTextNode defined? Quote Link to comment Share on other sites More sharing options...
sky Posted January 28, 2007 Author Share Posted January 28, 2007 I want ---$tnode to be a text node--- that is appended to my $nameNode nodethat is then appended to my $rootNode and then ultimate saved in my $dom andsaved 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 28, 2007 Share Posted January 28, 2007 $dom = new DomDocument;This is you creating an object.You might have to do:$textNode= new TextNode();$textNode=$dom->createTextNode("Thomas");Post the code for the createTextNode() function? Quote Link to comment Share on other sites More sharing options...
sky Posted January 29, 2007 Author Share Posted January 29, 2007 Here is the place I found the createTextNode function.http://us2.php.net/manual/en/function.dom-domdocument-createtextnode.phpAm I using it wrong? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 After $textNode=$dom->createTextNode("Thomas");Addprint_r($textNode);What does it say? Quote Link to comment Share on other sites More sharing options...
sky Posted January 29, 2007 Author Share Posted January 29, 2007 It prints to the browser:DOMText Object ( ) Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 So it looks like the object isn't being created properly, since it has no properties. I don't really understand what you're trying to do here. What is "Thomas"? What is a textnode anyway? Gah! Quote Link to comment Share on other sites More sharing options...
sky Posted January 29, 2007 Author Share Posted January 29, 2007 I'm sorry.All I was trying to do was create an $dom object to append my xml fileI 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 appendto the <person> element?Did I create the $rootNode correctly? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 I can't help you, maybe someone else can. Best of luck. Quote Link to comment Share on other sites More sharing options...
sky Posted January 29, 2007 Author Share Posted January 29, 2007 thanks for trying Quote Link to comment 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.