Michael,

Just before lightning the candles for Chrismas eve, I do have another short reaction to your last answer.
Yesterday I was too excited by the news of the fixed DTD revalidation (it works great).


Michael Glavassevich heeft op vrijdag, 23 dec 2005 om 18:54 (Europe/Amsterdam) het volgende geschreven:
In an LSParser context the default value of the defer node expansion
feature is *false*. It has to have this value in order for the
implementation to work correctly since an LSParser must be capable of
passing new nodes to an LSParserFilter before inserting them into the
tree. This DOM Level 3 feature just doesn't work with a deferred DOM, so
though I'm not sure why you weren't able to set the feature you probably
wouldn't want to change its value anyway.

Sorry, I did not tested this well. I can set it. See my program below.


Anyhow, there's really no need for the LSParser to support the
current-element-node property. When there's an error, the DOMError
reported to your error handler should contain the related node in the
DOMLocator.

I think this does not work like expected. In the normalizeDocument it is ok.
But during a normal parse you only get linenumbers etc. The related node always gives null.
So may be this is a real bug. You can just run the program to see it yourself.


Regards and have a nice ChristMas
Dick Deneer



Output:
Program started
Error Attribute "to" is required and must be specified for element type "note".
LineNr 1
Node null
Error Attribute "toe" must be declared for element type "note".
LineNr 1
Node null
Program ended

Program:

import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.DOMError;
import org.w3c.dom.DOMErrorHandler;
import org.w3c.dom.Document;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSParser;

public class TestErrorNode
{
final static String content =
"<?xml version=\"1.0\"?>" +
"<!DOCTYPE note [" +
"<!ELEMENT note (heading)> " +
"<!ATTLIST note to CDATA #REQUIRED> " +
"<!ELEMENT heading (#PCDATA)> " +
"]>" +
"<note toe=\"Deneer\"> <heading>Reminder</heading></note>";


public static void main(String[] args) throws Exception
{
//give file as input

System.out.println("Program started");
System.setProperty(DOMImplementationRegistry.PROPERTY,

"org.apache.xerces.dom.DOMXSImplementationSourceImpl");
DOMImplementationRegistry registry = DOMImplementationRegistry
.newInstance();
DOMImplementationLS impl = (DOMImplementationLS) registry

.getDOMImplementation("psvi");
LSParser parser = impl.createLSParser(
DOMImplementationLS.MODE_SYNCHRONOUS, null);
LSInput input = impl.createLSInput();
input.setStringData(content);
DOMConfiguration config = parser.getDomConfig();
config.setParameter("validate", Boolean.TRUE);
try
{
config.setParameter(
"http://apache.org/xml/features/dom/defer-node-expansion",
Boolean.FALSE);
}
catch(Exception e)
{
System.out.println("Cannot set deferred Node to false");
System.out.println(e);
}


DOMErrorHandler sh = new DOMErrorHandler()
{

public boolean handleError(DOMError e)
{
// Auto-generated method stub
System.out.println("Error " + e.getMessage());
System.out.println("LineNr " + e.getLocation().getLineNumber());
System.out.println("Node " + e.getLocation().getRelatedNode());
return false;
}
};
config.setParameter("error-handler", sh);

Document document = parser.parse(input);



System.out.println("Program ended");
}
}



Reply via email to