Hello there,

This question is about pulling PSVI information out of xerces SAX Parser. I have the following xml document (a simplified version):

<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
  <NewDataSet xmlns="">
    <Table diffgr:id="Table1" msdata:rowOrder="0">
      <CrawlID>1</CrawlID>
      <protocol>http://</protocol>
    </Table>
  </NewDataSet>
</diffgr>

and the following schema (again simplified version) :

<xs:schema id="NewDataSet" xmlns="" xmlns:xs=" http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Table" msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Table">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="CrawlID" type="xs:int" minOccurs="0"/>
              <xs:element name="port" type="xs:string" minOccurs="0"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

I want to be able to pull PSVI information out of the parser when validating the given xml document against the schema using SAX. I define an extension to
DefaultHandler class and in the constructor, I initialize the parser as:

<code>
..
private InputSource _xmlSource;
private Source _schemaSrc;
private PSVIProvider _psviProvider;
...
// inside the constructor:
SAXParserFactory factory = SAXParserFactory.newInstance();
// set features
factory.setValidating(true);
factory.setNamespaceAware(true);
factory.setFeature( http://xml.org/sax/features/namespace-prefixes, true);
factory.setFeature("http://apache.org/xml/features/validation/schema", true);
factory.setFeature ("http://apache.org/xml/features/validation/schema/augment-psvi", true);

// set schema
factory.setSchema(SchemaFactory.newInstance (XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(_schemaSrc));

// get the parser and PSVIProvider.      
SAXParser parser = factory.newSAXParser();
_psviProvider = (PSVIProvider) parser.getXMLReader();           

//  now parse.      
parser.parse(_xmlSrc, this);
</code>

To get the PSVI values, I insert the following code in my endElement event handler:

<code>
ElementPSVI psvi = _psviProvider.getElementPSVI();
if (psvi != null) {
     // If there was an element content
  Object value = psvi.getActualNormalizedValue();
  short type = psvi.getActualNormalizedValueType();
  if(value != null) {
    // do something
  }
}
</code>

The problem I face is that value object returned by psvi.getActualNormalizedValue() is always NULL. Now, there are a couple of validation errors that are reported for the Table element of the xml, however, that does not stop parsing. The errors have to do with the parser not recognizing the attributes of 'Table' element.

So, my question, do you have any pointers as to how I can get the PSVI information. Am I doing something clearly wrong? Or is there something very wrong with my xml/schema due to which the parser cannot obtain this information? I would appreciate any help.

Adil

Reply via email to