Esempio n. 1
0
static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding)
{
 /* Add the XML declaration as a tag. */

 currenttype=NULL;
 elementType_function("xsd:element",XMLPARSE_TAG_START|XMLPARSE_TAG_END,"xml","xmlDeclaration",NULL,NULL);
 complexType_function("xsd:complexType",XMLPARSE_TAG_START,"xmlDeclaration");
 attributeType_function("xsd:attribute",XMLPARSE_TAG_START|XMLPARSE_TAG_END,"version",NULL);
 attributeType_function("xsd:attribute",XMLPARSE_TAG_START|XMLPARSE_TAG_END,"encoding",NULL);
 complexType_function("xsd:complexType",XMLPARSE_TAG_END,NULL);
 currenttype=NULL;

 return(0);
}
Esempio n. 2
0
int main(int argc,char **argv)
{
 int i,j,k;

 if(ParseXML(stdin,xml_toplevel_tags,XMLPARSE_UNKNOWN_ATTR_IGNORE))
   {
    fprintf(stderr,"Cannot parse XML file - exiting.\n");
    exit(1);
   }

 /* Add the XML declaration as a tag. */

 currenttype=NULL;
 elementType_function("xsd:element",XMLPARSE_TAG_START|XMLPARSE_TAG_END,"xml","xmlDeclaration",NULL,NULL);
 complexType_function("xsd:complexType",XMLPARSE_TAG_START,"xmlDeclaration");
 attributeType_function("xsd:attribute",XMLPARSE_TAG_START|XMLPARSE_TAG_END,"version",NULL);
 attributeType_function("xsd:attribute",XMLPARSE_TAG_START|XMLPARSE_TAG_END,"encoding",NULL);
 complexType_function("xsd:complexType",XMLPARSE_TAG_END,NULL);

 /* Sort the tags */

 sorttags:

 for(i=0;i<ntagsx;i++)
   {
    for(j=0;j<tagsx[i]->nsubtagsx;j++)
      {
       for(k=0;k<ntagsx;k++)
          if(tagsx[i]->subtagsx[j]==tagsx[k])
             break;

       if(i<k)
         {
          xmltagx *temp=tagsx[i];

          tagsx[i]=tagsx[k];

          tagsx[k]=temp;

          goto sorttags;
         }
      }
   }

 /* Print the header */

 printf("/***************************************\n");
 printf(" An automatically generated skeleton XML parser.\n");
 printf("\n");
 printf(" Automatically generated by xsd-to-xmlparser.\n");
 printf(" ***************************************/\n");
 printf("\n");
 printf("\n");
 printf("#include <stdio.h>\n");
 printf("\n");
 printf("#include \"xmlparse.h\"\n");

 /* Print the function prototypes */

 printf("\n");
 printf("\n");
 printf("/* The XML tag processing function prototypes */\n");
 printf("\n");

 for(i=ntagsx-1;i>=0;i--)
   {
    printf("static int %s_function(const char *_tag_,int _type_",safe(tagsx[i]->type));

    for(j=0;j<tagsx[i]->nattributes;j++)
       printf(",const char *%s",safe(tagsx[i]->attributes[j]));

    printf(");\n");
   }

 /* Print the xmltag variables */

 printf("\n");
 printf("\n");
 printf("/* The XML tag definitions */\n");

 for(i=0;i<ntagsx;i++)
   {
    printf("\n");
    printf("/*+ The %s type tag. +*/\n",tagsx[i]->type);
    printf("static xmltag %s_tag=\n",safe(tagsx[i]->type));
    printf("              {\"%s\",\n",tagsx[i]->name);

    printf("               %d, {",tagsx[i]->nattributes);
    for(j=0;j<tagsx[i]->nattributes;j++)
       printf("%s\"%s\"",(j?",":""),tagsx[i]->attributes[j]);
    printf("%s},\n",(tagsx[i]->nattributes?"":"NULL"));

    printf("               %s_function,\n",safe(tagsx[i]->type));

    printf("               {");
    for(j=0;j<tagsx[i]->nsubtagsx;j++)
       printf("&%s_tag,",safe(tagsx[i]->subtagsx[j]->type));
    printf("NULL}};\n");
   }

 printf("\n");
 printf("\n");
 printf("/*+ The complete set of tags at the top level. +*/\n");
 printf("static xmltag *xml_toplevel_tags[]={");
 printf("&%s_tag,",safe(tagsx[ntagsx-1]->type));
 printf("&%s_tag,",safe(tagsx[ntagsx-2]->type));
 printf("NULL};\n");

 /* Print the functions */

 printf("\n");
 printf("\n");
 printf("/* The XML tag processing functions */\n");

 for(i=0;i<ntagsx;i++)
   {
    printf("\n");
    printf("\n");
    printf("/*++++++++++++++++++++++++++++++++++++++\n");
    if(i==(ntagsx-1))            /* XML tag */
       printf("  The function that is called when the XML declaration is seen\n");
    else
       printf("  The function that is called when the %s XSD type is seen\n",tagsx[i]->type);
    printf("\n");
    printf("  int %s_function Returns 0 if no error occured or something else otherwise.\n",safe(tagsx[i]->type));
    printf("\n");
    printf("  const char *_tag_ Set to the name of the element tag that triggered this function call.\n");
    printf("\n");
    printf("  int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.\n");
    for(j=0;j<tagsx[i]->nattributes;j++)
      {
       printf("\n");
       printf("  const char *%s The contents of the '%s' attribute (or NULL if not defined).\n",safe(tagsx[i]->attributes[j]),tagsx[i]->attributes[j]);
      }
    printf("  ++++++++++++++++++++++++++++++++++++++*/\n");
    printf("\n");

    printf("static int %s_function(const char *_tag_,int _type_",safe(tagsx[i]->type));

    for(j=0;j<tagsx[i]->nattributes;j++)
       printf(",const char *%s",safe(tagsx[i]->attributes[j]));

    printf(")\n");

    printf("{\n");

    if(i==(ntagsx-1))            /* XML tag */
      {
       printf(" printf(\"<?%%s\",_tag_);\n");
       for(j=0;j<tagsx[i]->nattributes;j++)
         {
          char *safename=safe(tagsx[i]->attributes[j]);
          printf(" if(%s) printf(\" %s=\\\"%%s\\\"\",ParseXML_Encode_Safe_XML(%s));\n",safename,tagsx[i]->attributes[j],safename);
         }
       printf(" printf(\" ?>\\n\");\n");
      }
    else
      {
       printf(" printf(\"<%%s%%s\",(_type_==XMLPARSE_TAG_END)?\"/\":\"\",_tag_);\n");
       for(j=0;j<tagsx[i]->nattributes;j++)
         {
          char *safename=safe(tagsx[i]->attributes[j]);
          printf(" if(%s) printf(\" %s=\\\"%%s\\\"\",ParseXML_Encode_Safe_XML(%s));\n",safename,tagsx[i]->attributes[j],safename);
         }
       printf(" printf(\"%%s>\\n\",(_type_==(XMLPARSE_TAG_START|XMLPARSE_TAG_END))?\" /\":\"\");\n");
      }

    printf(" return(0);\n");
    printf("}\n");
   }

 /* Print the main function */

 printf("\n");
 printf("\n");
 printf("/*++++++++++++++++++++++++++++++++++++++\n");
 printf("  A skeleton XML parser.\n");
 printf("  ++++++++++++++++++++++++++++++++++++++*/\n");
 printf("\n");
 printf("int main(int argc,char **argv)\n");
 printf("{\n");
 printf(" if(ParseXML(stdin,xml_toplevel_tags,XMLPARSE_UNKNOWN_ATTR_WARN))\n");
 printf("    return(1);\n");
 printf(" else\n");
 printf("    return(0);\n");
 printf("}\n");

 return(0);
}