getElementsByTagName problem

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

Post Reply
mavedog21
Forum Newbie
Posts: 23
Joined: Thu Dec 21, 2006 1:27 pm

getElementsByTagName problem

Post by mavedog21 »

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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

http://php.net/manual/en/function.domdo ... agname.php states the method name is get_elements_by_tagname()
mavedog21
Forum Newbie
Posts: 23
Joined: Thu Dec 21, 2006 1:27 pm

Post by mavedog21 »

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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Without underscores is not listed in the manual that I've seen... so you would never use it.
mavedog21
Forum Newbie
Posts: 23
Joined: Thu Dec 21, 2006 1:27 pm

Post by mavedog21 »

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Take a look at the methods provided by each API.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

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 »

thanks for clearing that up it was my mistake in typing.
Appreciate the help.
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post by TheMoose »

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 :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

getElementsByTagName() is a PHP function.
Post Reply