Menu

Loading N grammars, then choosing the good one to encode/decode

2013-03-07
2013-03-14
  • Denis Froschauer

    Hi Rumen,
    I'm developing a server that can encode documents N different grammars. These grammars are known and present in n EXI grammar files.
    I call generateSchemaInformedGrammars() with these N grammars, with success.
    The idea is to do that work only at start time, and only one time.

    First question : I want to encode a document with one of these grammars. I know the name of the grammar.
    Is it a way to specify which grammar is needed to encode the document ? (I think that, in v5.0, EXIP uses only the first grammar defined in the table passed to generateSchemaInformedGrammars()).

    Second question : I will use SCHEMA_ID to store the grammar name into the EXI document. How the decoder can read to this SCHEMA_ID in the header ?

    Third question : Knowing the grammar (after reading the header), how to decode the document using it ?

    Denis

     
    • Rumen Kyusakov

      Rumen Kyusakov - 2013-03-14

      Hi Denis,

      generateSchemaInformedGrammars() is building an EXIPSchema object from a XML schema i.e. XSD. It accepts n EXI grammar files as a XSD can have <import> statements that are links to sub XSD. Look at the exipe sample for example. The first XSD in the list passed to generateSchemaInformedGrammars() should be the root XSD meaning all the rest should be accessed through <import> statements from it. To generate the grammar only once you can use exipg if the gramamrs are known in compile time. Otherwise you just need to preserve the EXIPSchema object through different processings - you can use it multiple times for encoding/decoding and just destroy it at the end of the application.That being said here are some more hints for your questions -

      First question: You need different EXIPSchema object for the different XSDs that are not connected through <xs:import>. It looks to me that how you handle the selection of the particular EXI encoded schema files is application specific and not much related to how exip handles them - correct me if I'm wrong.

      Second question: After successful parseHeader(); invocation the parser.strm.header.opts.schemaID should contain the value of SCHEMA_ID field if encoded. (all other header options are also available in parser.strm.header)

      Third question: Knowing the SCHEMA_ID your application needs to have some mapping between the SCHEMA_ID and the corresponding EXIPSchema object. Note that the content of SCHEMA_ID is application specific and so is this mapping.

      Hope that helps.

      // Rumen

       
  • Denis Froschauer

    A proposal to permit the application to retrieve a schema by its schemaID.

    The app has to implement the hook function :

    EXIPSchema g_schema;
    static EXIPSchema sample_retrieveSchema(void app_data) {
    struct appData appD = (struct appData) app_data;
    EXIheader *hdr = &appD->parser->strm.header;

        if      (!hdr->has_options)
                return  NULL;
        if      (isStringEmpty(&hdr->opts.schemaID))
                return  NULL;
    

    // generateSchemaInformedGrammars (buffer, cnt, SCHEMA_FORMAT_XSD_EXI, NULL, &g_schema);

        return &g_schema;
    

    }

     

    Last edit: Denis Froschauer 2013-03-14
    • Rumen Kyusakov

      Rumen Kyusakov - 2013-03-14

      Hi Denis,

      Very good idea!
      I think it should also replace the current way of setting the grammar through initParser();

      I'll create a feature request and add it to the codebase soon.

      Thanks!

      // Rumen

       

Anonymous
Anonymous

Add attachments
Cancel