Page 1 of 1
getElementsByTagName problem
Posted: Fri Jan 26, 2007 3:27 pm
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
Posted: Fri Jan 26, 2007 3:48 pm
by feyd
It's not a method of $doc.
What is $doc?
Posted: Fri Jan 26, 2007 3:54 pm
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
Posted: Fri Jan 26, 2007 4:13 pm
by feyd
Posted: Fri Jan 26, 2007 4:27 pm
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?
Posted: Fri Jan 26, 2007 4:33 pm
by feyd
Without underscores is not listed in the manual that I've seen... so you would never use it.
Posted: Fri Jan 26, 2007 4:40 pm
by mavedog21
Posted: Fri Jan 26, 2007 4:43 pm
by feyd
DOM is for PHP 5, DOMXML is for PHP 4. DOM has getElementsByTagName(), DOMXML has get_elements_by_tagname()
Posted: Fri Jan 26, 2007 4:50 pm
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?
Posted: Fri Jan 26, 2007 5:31 pm
by feyd
Take a look at the methods provided by each API.
Posted: Sat Jan 27, 2007 12:05 am
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.
Posted: Mon Jan 29, 2007 12:54 pm
by mavedog21
thanks for clearing that up it was my mistake in typing.
Appreciate the help.
Posted: Mon Jan 29, 2007 1:37 pm
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

Posted: Mon Jan 29, 2007 3:01 pm
by RobertGonzalez