Guest claudio.cads Posted March 20, 2008 Share Posted March 20, 2008 Hi,I have an XML and its DTD but I noticed that if my XML have tags that are not described in its DTD no error is returned. I thought that the DTD would return some warning message reporting this. Does anyone can help me ?The simple example below can be used to reproduce my scenario. Note that the tag ENTIDADE2 is not declared in the DTD file but the XML file is opened correctly in the internet explorer, for example.Cheers,Cláudio.*** test.xml<?xml version="1.0"?><!DOCTYPE XML SYSTEM "test.dtd"><XML><ENTIDADE2 atributo="valoratributo">valortag</ENTIDADE2></XML>*** test.dtd<!ELEMENT XML (ENTIDADE)><!ELEMENT ENTIDADE (#PCDATA)> Link to comment Share on other sites More sharing options...
boen_robot Posted March 20, 2008 Share Posted March 20, 2008 An XML parser will parse the XML if DTD validation is off or non existent.If you try to load the XML with DTD validaiton on, you'll see your error. In PHP for example, you can do: $dom = new DOMDocument;//By default, this won't cause an error$dom->load('test.xml');//This boolean property does all the magic$dom->validateOnParse = true;//The below line will now cause an error$dom->load('test.xml'); Link to comment Share on other sites More sharing options...
Synook Posted March 21, 2008 Share Posted March 21, 2008 The DTD doesn't actually "return" anything, it just tells agents what the XML document is supposed to look like. However, running that through a validator should generate a warning. Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted March 21, 2008 Share Posted March 21, 2008 Because most browser XML parsers check only for well-formedness, they aren't validating parsers. Invalid, but well-formed XML will not generate an error through non-validating parsers. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.