Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This application parses XML schema file and generates C source code for parsing xml file.

License

NotificationsYou must be signed in to change notification settings

kiishor/xml_code_generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a source code generator tool forxml parser in c. This application parses XML schema fileand generates C source code that can be used for parsing XML file.

It generatesxs_element_t data structure inC based on the XML schema file. This structure contains all theschema properties of XML elements such as element name, its child elements, attributes, content type, etc..It also contains the tree structure of XML elements in the schema.The parser uses thisxs_element_t structure for validating the input XML file against XML schema constraints (rules).

How to use

This is a command line tool, it takes XML schema file as input and generates c source code.The simplest way to use is,

xml_code_generator.exe food.xsd

The tool generates two files

  • food.h : This file containsfood_t structure created from schema to store the content of XML.
  • food.c : This file containsxs_element_t tree structure generated from schema.

food.xsd

Input XML schema.

<?xml version="1.0"?><xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:elementname="food">    <xs:complexType>      <xs:sequence>        <xs:elementtype="xs:string"name="name"/>        <xs:elementtype="xs:float"name="price"/>        <xs:elementtype="xs:string"name="description"/>        <xs:elementtype="xs:unsignedInt"name="calories"/>      </xs:sequence>    </xs:complexType>  </xs:element></xs:schema>

food.h

Header file contains the C structurefood_t based on the data structure of input XML schema.This structure is useful to store the extracted content from the XML file byXML parser.

typedefstruct{char*name;floatprice;char*description;uint32_tcalories;}food_t;

food.c

Source file contains thexs_element_t for each element in the schema.

food_root is thexs_element_t variable for root element "food".It represents all the XML element properties of "food" element in schema.Also, it holds the address of its attributes (food_attribute) and child elements (food_descendant).

constxs_element_tfood_root={    .Name.String="food",    .Name.Length=4,    .MinOccur=1,    .MaxOccur=1,    .Target.Type=EN_RELATIVE,    .Target.Offset=0,    .Content.Type=EN_NO_XML_DATA_TYPE,    .Attribute_Quantity=2,    .Attribute=food_attribute,    .Child_Quantity=4,    .Child_Order=EN_SEQUENCE,    .Child=food_descendant,};

food_descendant is an array ofxs_element_t. It holds all the child elements offood element.

staticconstxs_element_tfood_descendant[]={    [0].Name.String="name",    [0].Name.Length=4,    [0].MinOccur=1,    [0].MaxOccur=1,    [0].Target.Type=EN_RELATIVE,    [0].Target.Offset= offsetof(food_t,name),    [0].Content.Type=EN_STRING_DYNAMIC,    [0].Content.Facet.String.MinLength=0,    [0].Content.Facet.String.MaxLength=4294967295,    ...    [3].Name.String="calories",    [3].Name.Length=8,    [3].MinOccur=1,    [3].MaxOccur=1,    [3].Target.Type=EN_RELATIVE,    [3].Target.Offset= offsetof(food_t,calories),    [3].Content.Type=EN_UNSIGNED,    [3].Content.Facet.Uint.MinValue=0,    [3].Content.Facet.Uint.MaxValue=4294967295,};

food_attribute is an array ofxs_attribute_t. It holds all the attributes offood element.

staticconstxs_attribute_tfood_attribute[]={    [0].Name.String="xmlns:xsi",    [0].Name.Length=9,    [0].Use=EN_OPTIONAL,    [1].Name.String="xsi:noNamespaceSchemaLocation",    [1].Name.Length=29,    [1].Use=EN_OPTIONAL,};

Address offood_root is passed toxml parser along with XML string to parse.For further information on how to use these food.c and food.h for parsing XML file referfood example

Command line options

Callback

-b or--callback

Code generator includesCallback member in eachxs_element_t variables of generated code.

By defaultCallback member variable is disabled in thexs_element_t structure to save code space.Hence, to avoid compilation error, code generator also by default omits theCallback member in the generated code.Use this option in the command line when you have enabledCallback member in the XML parser.

Dynamic memory allocation

-d or--dynamicCode generator uses dynamic addressing method (EN_DYNAMIC) for XML element that can occur multiple times (maxOccurs > 1) in an XML file.

By default code generator uses relative addressing method (EN_RELATIVE) as a target addressing method for all the XML elements.The dynamic addressing method enables user to allocate memory at runtime to store the XML data.

Enable context

-c or--context

Code generator includescontext argument in the signature ofallocate callback function.

By default user defined context in the XML parser is disabled to save code space.Hence, to avoid compilation error, code generator also by default omits thecontext argumentin theallocate callback function.Use this option in the command line when you have enabled thecontext argument in the XML parser.

More

About

This application parses XML schema file and generates C source code for parsing xml file.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp