i've turned on the schema and validation features, and set a schema to my html,
but getElementById still doesn't work (i'm using the latest of xerces, xalan
and tagsoup, xhtml1-transitional.dtd and entities are saved locally.
this is my html:
<html>
<body>
<div id="foo">hello</div>
</body>
</html>
this is my code:
import org.apache.xalan.xsltc.trax.SAX2DOM;
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
import org.ccil.cowan.tagsoup.Parser;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class Test {
public static class HTMLDocumentBuilderFactory extends
DocumentBuilderFactoryImpl {
public HTMLDocumentBuilderFactory() throws SAXException,
ParserConfigurationException {
setValidating(true);
setFeature("http://apache.org/xml/features/validation/schema", true);
setFeature("http://xml.org/sax/features/validation", true);
}
}
public final static void main(String[] args) throws Exception {
Parser p = new Parser();
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
HTMLDocumentBuilderFactory.class.getName());
SAX2DOM sax2dom = new SAX2DOM();
Document doc = (Document)sax2dom.getDOM();
DOMConfiguration config = doc.getDomConfig();
config.setParameter("schema-type","http://www.w3.org/TR/REC-xml");
config.setParameter("schema-location", "/tmp/xhtml1-transitional.dtd");
p.setContentHandler(sax2dom);
InputSource docsrc = new InputSource("/tmp/test.html");
p.parse(docsrc);
System.out.println(doc.getElementById("foo"));
}
}
thanx,
ittay
--
===================================
Ittay Dror
openQRM Team Leader,
R&D, Qlusters Inc.
[EMAIL PROTECTED]
+972-3-6081994 Fax: +972-3-6081841
http://www.openQRM.org
- Keeps your Data-Center Up and Running
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]