PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mavedog21
Forum Newbie
Posts: 23 Joined: Thu Dec 21, 2006 1:27 pm
Post
by mavedog21 » Fri Jan 26, 2007 3:27 pm
Hello,
when I try to use
Code: Select all
$root = $doc->getElementsByTagName('person');
in my php file it seems to output this error:
Fatal error: Call to undefined function: getelementsbytagname() in /home/
I've tried it in both php 4 and php 5
can somebody tell me what is wrong with this line?
thanks,
sky
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 26, 2007 3:48 pm
It's not a method of $doc.
What is $doc?
mavedog21
Forum Newbie
Posts: 23 Joined: Thu Dec 21, 2006 1:27 pm
Post
by mavedog21 » Fri Jan 26, 2007 3:54 pm
here is where it's from.
does it matter if I use dom instead as the variable?
Code: Select all
$doc = domxml_new_doc("theXML.xml");
//$doc->load("theXML.xml"); -----this has problems also-----
// creates a dom object and loads "theXML.xml" file into it
$rootNode = $doc->getElementsByTagName('person');
// sets $rootNode value as the xml root node
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 26, 2007 4:13 pm
mavedog21
Forum Newbie
Posts: 23 Joined: Thu Dec 21, 2006 1:27 pm
Post
by mavedog21 » Fri Jan 26, 2007 4:27 pm
Thanks,
Is getElementsByTagName() for php4 or php5 ???
why or when would you use it (getElementsByTagName()) I guess is my question
compared to using this get_elements_by_tagname?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 26, 2007 4:33 pm
Without underscores is not listed in the manual that I've seen... so you would never use it.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 26, 2007 4:43 pm
DOM is for PHP 5, DOMXML is for PHP 4. DOM has getElementsByTagName(), DOMXML has get_elements_by_tagname()
mavedog21
Forum Newbie
Posts: 23 Joined: Thu Dec 21, 2006 1:27 pm
Post
by mavedog21 » Fri Jan 26, 2007 4:50 pm
so if I'm using php5 the text would be ok like this?
Code: Select all
$dom= new DomDocument();
$dom->load("theXML.xml");
$root = $dom->getElementsByTagName('person');
that would point to 'persons' in my xml file?
Code: Select all
<persons>
<name>tom</name>
<age>29</age>
</person>
would that be the same for appendChild and append_child?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 26, 2007 5:31 pm
Take a look at the methods provided by each API.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jan 27, 2007 12:05 am
mavedog21 wrote: that would point to 'persons' in my xml file?
No, to a collection of 'person' elements. And you document wouldnÄt be parsed, because <persons> does not match </person>. Since you made the mistake twice in your text I thought it worth mentioning.
mavedog21
Forum Newbie
Posts: 23 Joined: Thu Dec 21, 2006 1:27 pm
Post
by mavedog21 » Mon Jan 29, 2007 12:54 pm
thanks for clearing that up it was my mistake in typing.
Appreciate the help.
TheMoose
Forum Contributor
Posts: 351 Joined: Tue May 23, 2006 10:42 am
Post
by TheMoose » Mon Jan 29, 2007 1:37 pm
getElementsByTagName (spelled just like that) is the Javascript version, so maybe that's what you were thinking of? You got it fixed, so that's all that matters