  | |  | Accessing PSVI through DOM | Accessing PSVI through DOM 2003-05-08 - By Bill Raudabaugh
I've read the doc and looked through the archive of this list for hints on how to access PSVI through the DOM interface, and while I seem to be very close to getting it to work, I've hit a brick wall.
The class below is my test case. The XML schema is definitely operating because the error handler routines are being called for intentional problems that I've put in my XML for testing. And the cast of the node to ElementPSVI works fine. But the PSVI information seems doesn't appear to have been filled in by the validator. All of the nodes show a validity of 0 -> not known.
I know there are some smart folks out there that have managed to access PSVI via DOM. If anyone has any ideas on why my validity is always 0 I would definitely appreciate it.
Bill
import org.apache.xerces.parsers.DOMParser; import org.apache.xerces.xni.psvi.*; import org.apache.xerces.impl.xs.psvi.*; import org.w3c.dom.*; import org.xml.sax.*; import java.io.ByteArrayInputStream; import javax.xml.parsers.*;
public class SchemaTest implements ErrorHandler {
public static void main(String argv[]) throws Exception { Document doc; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(true);
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage ", "http://www.w3.org/2001/XMLSchema");
factory.setAttribute("http://apache.org/xml/properties/dom/document-class-na me", "org.apache.xerces.dom.PSVIDocumentImpl");
DocumentBuilder parser = factory.newDocumentBuilder(); parser.setErrorHandler(new SchemaTest()); String xml = "<scheduler" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + " xsi:noNamespaceSchemaLocation=\"http://adivo.com/Scheduler.xsd\">" + "<jobs><group><job></job></group></jobs></scheduler>"; ByteArrayInputStream xmlStream = new ByteArrayInputStream(xml.getBytes()); InputSource source = new InputSource(xmlStream); doc = parser.parse(source); checkPSVI(doc.getDocumentElement()); }
private static void checkPSVI(Node node) { ElementPSVI elem = (ElementPSVI) node; System.out.println(node.getNodeName() + " validity=" + elem.getValidity()); NodeList children = node.getChildNodes(); int length = children.getLength(); for (int i=0; i < length; i++) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) checkPSVI(child); } }
public void warning(SAXParseException ex) { System.out.println(ex.toString()); }
public void error(SAXParseException ex) { System.out.println(ex.toString()); }
public void fatalError(SAXParseException ex) { System.out.println(ex.toString()); } }
Bill Raudabaugh Adivo Ltd email: bill@(protected) Phone: (614)766-6870 Fax: (614)573-7101
--------------------------------------------------------------------- To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected) For additional commands, e-mail: xerces-j-user-help@(protected)
|
|
 |