Jump to content


Photo

[SOLVED] getElementById STILL not working like it should... :(


  • Please log in to reply
2 replies to this topic

#1 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 20 August 2006 - 11:17 AM

Argh.

Fatal error: Uncaught exception 'Exception' with message 'Node not found.' in E:\John\Sites\CurrentDev\johnkleijn.nl\lib\domxml.class.php:45 Stack trace: #0 E:\John\Sites\CurrentDev\johnkleijn.nl\lib\env.class.php(83): DomXml->getElementById('log_errors') #1 E:\John\Sites\CurrentDev\johnkleijn.nl\lib\backbone.class.php(27): Env->get('log_errors') #2 E:\John\Sites\CurrentDev\johnkleijn.nl\index2.php(6): Backbone->__construct('transitional', 'iso-8859-1') #3 {main} thrown in E:\John\Sites\CurrentDev\johnkleijn.nl\lib\domxml.class.php on line 45


As you can see by looking at the backtrace, the exeption is thrown from DomXml->getElementById.

DomXml->getElementById('log_errors')
<?php
	public function getElementById($id) {
		if($this->domDoc->validate()) {
			if(!$node = $this->domDoc->getElementById($id)) {
				throw new Exception('Node not found.');
			}
				else {
				return $node;
			}	
		}
			else {
			return false;	
		}
	}
?>

While:
<error_flag id="log_errors">true</error_flag>
and the attribute id is specified to be of type ID:
<!ENTITY % idattr "id ID #IMPLIED" >
<!ELEMENT error_flag (#PCDATA)> 
<!ATTLIST error_flag  %idattr; >


Obviously, the XML file validates, or the exeption could never have been thrown. I just don't get why I don't get the freakin node to return!

#2 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 20 August 2006 - 12:22 PM

What the $#!@^&%? is going on?

I messed up the DTD intentionally to see what would happen:

<!-- <!ELEMENT error_flag (#PCDATA)> -->
<!ATTLIST error_flag id ID #REQUIRED >

When tested with Dreamweavers validation it retruns the correct error: "unknown element error_flag" (before it didn't return anything), but when I try to run the test script, I get NO validation errors, just the same exeption! That doesn't make any sense!

#3 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 20 August 2006 - 01:08 PM

Never mind, I'm an idiot.  ;D

In Env::__construct() I forget to load the XML file, so I was trying to get nodes out of an empty document... ::)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users