列表 3. autoXml 代码生成

以下是 polygon.dtdx 文件

<!ELEMENT POLYGON (DESCRIPTION? POINT+)>
<!ATTLIST POLYGON id CDATA #REQUIRED>
<!ELEMENT DESCRIPTION (#PCDATA)>
<!ELEMENT POINT>
<!ATTLIST POINT x INT #REQUIRED>
<!ATTLIST POINT y INT #REQUIRED>
<!ATTLIST POINT z INT "0">

以及命令行

autoXml polygon.dtdx poly

生成 poly.h 如下

/* poly.h autoXml generated file */
#ifndef POLY_H
#define POLY_H

struct polyPolygon
   {
   struct polyPolygon *next;
   char *id;   /* Required */
   struct polyDescription *polyDescription;
      /** Optional (may be NULL). **/
   struct polyPoint *polyPoint;
      /** Non-empty list required. **/
   };

void polyPolygonSave(struct polyPolygon *obj,
     int indent, FILE *f);
/* Save polyPolygon to file. */

struct polyPolygon *polyPolygonLoad(char *fileName);
/* Load polyPolygon from file. */

struct polyDescription
    {
    struct polyDescription *next;
    char *text;
    };

void polyDescriptionSave(struct
     polyDescription *obj, int indent, FILE *f);
/* Save polyDescription to file. */

struct polyDescription
     *polyDescriptionLoad(char *fileName);
/* Load polyDescription from file. */

struct polyPoint
    {
    struct polyPoint *next;
    double x;  /* Required */
    double y;  /* Required */
    double z;  /* Defaults to 0 */
    };

void polyPointSave(struct polyPoint *obj,
    int indent, FILE *f);
/* Save polyPoint to file. */

struct polyPoint *polyPointLoad(char *fileName);
/* Load polyPoint from file. */

#endif /* POLY_H */
© . All rights reserved.