I apologize for having double posted this message.

Adil


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

<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) returned by the same web service:

<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. Moreover, it cannot recognize the root element diffgr:diffgram. I tried stipping out the diffgr:diffgram element and sending the data from NewDataSet onwards, but the root element declaration not found error persists.

So, my question is, do you have any pointers as to what am I doing wrong? is there something very wrong with my xml/schema due to which the parser cannot obtain this information? I would appreciate any help.

I read in some of the posts that the root element validation error happens because the external schema location property is not set. I am not sure how that applies to my case cuz I do not have these documents stored on disk, rather I have string readers generate InputSources that I feed to the parser.

Adil

Reply via email to