Jump to content

Archived

This topic is now archived and is closed to further replies.

448191

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

Recommended Posts

Argh.

[quote]
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[/quote]

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

[b]DomXml->getElementById('log_errors')[/b]
[code]<?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;
}
}
?>[/code]

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

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!

Share this post


Link to post
Share on other sites
What the $#!@^&%? is going on?

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

[code]<!-- <!ELEMENT error_flag (#PCDATA)> -->
<!ATTLIST error_flag id ID #REQUIRED > [/code]

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!

Share this post


Link to post
Share on other sites
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... ::)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.