-
Notifications
You must be signed in to change notification settings - Fork 2
/
food.c
108 lines (88 loc) · 6.13 KB
/
food.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* \file
* \brief Simple XML parser demo
* \author Nandkishor Biradar
* \date 18 April 2021
* Copyright (c) 2019-2022 Nandkishor Biradar
* https://github.com/kiishor
* Distributed under the MIT License, (See accompanying
* file LICENSE or copy at https://mit-license.org/)
*/
/*
* ------------------------------ INCLUDE FILES ------------------------------
*/
#include <stdlib.h>
#include <stdbool.h>
#include <float.h>
#include "food.h"
/*
* ----------------------------- GLOBAL VARIABLES -----------------------------
*/
//! Global variable to store content of food XML
food_t waffle;
static const xs_attribute_t food_attribute[];
static const xs_element_t food_descendant[];
//! Structure containing XML schema property of food (root) element.
const xs_element_t food_root =
{
.Name.String = "food", //!< name of XML element
.Name.Length = 4, //!< Length of name
.MinOccur = 1, //!< Minimum number of times an element shall occur in the XML
.MaxOccur = 1, //!< Maximum number of times an element can occur in the XML
.Content.Type = EN_NO_XML_DATA_TYPE, //!< This element doesn't hold any content
.Attribute_Quantity = 2, //!< Number of attributes of this element
.Attribute = food_attribute, //!< Address of structure containing attributes
.Child_Quantity = 4, //!< Number of child elements
.Child_Order = EN_SEQUENCE, //!< Order of child elements
.Child = food_descendant, //!< Address of structure holding child elements
};
//! Structure containing all the attributes of food (root) element
static const xs_attribute_t food_attribute[] =
{
[0].Name.String = "xmlns:xsi", //!< Name of XML attribute
[0].Name.Length = 9, //!< Length of attribute name
[0].Use = EN_OPTIONAL, //!< Usage of attribute in the XML. Required / Optional
[1].Name.String = "xsi:noNamespaceSchemaLocation", //!< Name of XML attribute
[1].Name.Length = 29, //!< Length of attribute name
[1].Use = EN_OPTIONAL, //!< Usage of attribute in the XML. Required / Optional
};
//! Structure containing all the child element of food (root) element.
static const xs_element_t food_descendant[] =
{
[0].Name.String = "name", //!< Name of XML element
[0].Name.Length = 4, //!< Length of name
[0].MinOccur = 1, //!< Minimum number of times an element shall occur in the XML
[0].MaxOccur = 1, //!< Maximum number of times an element can occur in the XML
[0].Target.Type = EN_STATIC, //!< Target address type is static. No dynamic memory allocation is required.
[0].Target.Address = &waffle.name, //!< Target address to store content of an element
[0].Content.Type = EN_STRING_DYNAMIC, //!< Content type is string that is allocated dynamically using malloc() by parser
[0].Content.Facet.String.MinLength = 0, //!< Minimum length of string
[0].Content.Facet.String.MaxLength = 4294967295, //!< Maximum possible length of a string
[1].Name.String = "price", //!< Name of XML element
[1].Name.Length = 5, //!< Length of element name
[1].MinOccur = 1, //!< Minimum number of times an element shall occur in the XML
[1].MaxOccur = 1, //!< Maximum number of times an element can occur in the XML
[1].Target.Type = EN_STATIC, //!< Target address type is static. No dynamic memory allocation is required
[1].Target.Address = &waffle.price, //!< Target address to store content of an element
[1].Content.Type = EN_DECIMAL, //!< Content type is decimal i.e. float
[1].Content.Facet.Decimal.MinValue = -3.40282e+038f, //!< Minimum possible value of an element
[1].Content.Facet.Decimal.MaxValue = 3.40282e+038f, //!< Maximum possible value of an element
[2].Name.String = "description", //!< Name of XML element
[2].Name.Length = 11, //!< length of name
[2].MinOccur = 1, //!< Minimum number of times an element shall occur in the XML
[2].MaxOccur = 1, //!< Maximum number of times an element can occur in the XML
[2].Target.Type = EN_STATIC, //!< Target address type is static. No dynamic memory allocation is required.
[2].Target.Address = &waffle.description, //!< Target address to store content of an element
[2].Content.Type = EN_STRING_DYNAMIC, //!< Content type is string that is allocated dynamically using malloc() by parser
[2].Content.Facet.String.MinLength = 0, //!< Minimum length of string
[2].Content.Facet.String.MaxLength = 4294967295, //!< Maximum possible length of a string
[3].Name.String = "calories", //!< Name of XML element
[3].Name.Length = 8, //!< length of name
[3].MinOccur = 1, //!< Minimum number of times an element shall occur in the XML
[3].MaxOccur = 1, //!< Maximum number of times an element can occur in the XML
[3].Target.Type = EN_STATIC, //!< Target address type is static. No dynamic memory allocation is required.
[3].Target.Address = &waffle.calories, //!< Target address to store content of an element
[3].Content.Type = EN_UINT32, //!< Content type is unsigned int
[3].Content.Facet.Uint.MinValue = 0, //!< Minimum possible value of an element
[3].Content.Facet.Uint.MaxValue = 4294967295, //!< Maximum possible value of an element
};