[xsd-users] A9 regression

Chris Gagneraud chgans at googlemail.com
Thu Nov 3 00:40:14 EDT 2016


Hi there,

Using xsd-cxx version A9 on Windows, I have some issues with the error
handlers, exceptions and schema validation.

In a nutshell, Here is my main:

-----------------------------------------------------------------
class ErrorHandler: public xml_schema::ErrorHandler
{
public:
    virtual bool handle (...)
    {
        cout << flush;
        cerr << endl
             << "Line " << line << ", Column " << column << ": " << message
             << endl << flush;
        return false;
    }
};

int main(int argc, char *argv[])
{
 try
 {
  xml_schema::Properties props;
  // FIXME: Use absolute path, otherwise the file path have to be
relative to the
  // path of the file we are parsing, not the current dir.
  props.schema_location ("http://webstds.ipc.org/2581", "IPC-2581B_V3.0.xsd");
  props.schema_location ("http://www.w3.org/XML/1998/namespace", "xml.xsd");
  cout << "Parsing " << argv[1] << "...";
  ErrorHandler errorHandler;
  unique_ptr<IPC_2581Type> ipc(iPC_2581(argv[1], errorHandler, 0, props));
  cout << " Done!" << endl;
 }
 catch (const xsd::cxx::tree::parsing<char> &e)
 {
    cout << flush;
    cerr << endl
           <<  "XSD Parsing error:\n" << e
           << endl << flush;
    return 1;
  }
 catch (const xsd::cxx::exception &e)
 {
    cout << flush;
    cerr << endl
           << "XSD Exception:\n" << e.what()
           << endl << flush;
 }
 return 0;
}
-----------------------------------------------------------------

Case 1: The schemas and the xml file are all in  the current folder,
when i execute my program on a non-compliant XML file I get:
-----------------------------------------------------------------
Parsing samples\test-3_r2.xml...
XSD Exception:
expected element not encountered
-----------------------------------------------------------------

Case 2: Same XML file, but schema not found, I get
-----------------------------------------------------------------
Parsing samples\test-3_r2.xml...
Line 0, Column 0: unable to open primary document entity
'E:\projects\ipc-parser/samples\nowhere\IPC-2581B_V3.0.xsd'
[!crash!] The program has unexpectedly finished.
-----------------------------------------------------------------

Case 3: Now, still with the wrong schema path, but this time returning
true in my handler:
-----------------------------------------------------------------
Parsing samples\test-3_r2.xml...
Line 0, Column 0: unable to open primary document entity
'E:\projects\ipc-parser/samples\nowhere\IPC-2581B_V3.0.xsd'
Line 2, Column 159: no declaration found for element 'IPC-2581'
Line 2, Column 159: attribute 'revision' is not declared for element 'IPC-2581'
XSD Parsing error:
instance document parsing failed
-----------------------------------------------------------------

Case 4: The schemas and the xml file are all in  the current folder,
non compliant XML file, and the handler returns true
-----------------------------------------------------------------
Parsing samples\test-3_r2.xml...
XSD Exception:
expected element not encountered
-----------------------------------------------------------------

Case 5: as Case 1 and 4 (schema found) but without error handler at all
-----------------------------------------------------------------
Parsing samples\test-3_r2.xml...
XSD Exception:
expected element not encountered
-----------------------------------------------------------------

Case 6: as Case 2 and 3 (schema not found) but without error handler at all
Parsing samples\test-3_r2.xml...
-----------------------------------------------------------------
XSD Parsing error:
:0:0 warning: unable to open primary document entity
'E:\projects\ipc-parser/samples\/nowhere/IPC-2581B_V3.0.xsd'
E:\projects\ipc-parser/samples\test-3_r2.xml:2:159 error: no
declaration found for element 'IPC-2581'
E:\projects\ipc-parser/samples\test-3_r2.xml:2:159 error: attribute
'revision' is not declared for element 'IPC-2581'
-----------------------------------------------------------------

So my question is how am i suppose to catch non-compliance error with
the error context (parsing context)? Shouldn't my error handler be
called for any kind of error?

As far as i remember my code worked correctly with v4.0.0 (I had to
use a strip-down version of the schema due to a bug in xsd-cxx).
My point is that i was able to report non-compliance error with
context information (line/column numbers).

Is this a regression or am I missing something?

Thanks,
Chris



More information about the xsd-users mailing list