[go: up one dir, main page]

Menu

[cde965]: / doc / datastruct.html  Maximize  Restore  History

Download this file

235 lines (210 with data), 7.4 kB

  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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="SourceForge presents the sxmlc project. sxmlc is an open source application. SourceForge provides the world's largest selection of Open Source Software. Simple XML parser written in C. \"Simple\" means that it does not implement all XML specifications, only the most widely used ones. It is not an attempt to re-write the fine 'libxmlc'! :)" />
<meta name="keywords" content="Open Source, Software, Development, Developers, Projects, SourceForge, All POSIX (Linux/BSD/UNIX-like OSes), 32-bit MS Windows (NT/2000/XP), C, XML, Developers, GNU Library or Lesser General Public License (LGPL), sxmlc" />
<title>SXMLC - Simple XML C parser - Data structures</title>
<style type="text/css">
body
{
background: url("prweb-sidebar.png") top left fixed no-repeat;
font-family: sans-serif;
line-height: 140%;
font-size: 90%;
}
a img
{
border-style: none;
text-decoration: none;
vertical-align: middle;
}
h1 { margin: 0 0 1em 5%; width: 80%; font-size: 160%; line-height: normal;}
small {margin: .5em 0 0 5%; font-size: 80%; position: relative; display: block;}
h3 { margin-top: 2em; font-size: 100%; }
h2 { margin-top: 1em; font-size: 120%; }
/* layout */
.host
{
position: absolute;
right: 1em;
top: 2em;
width: 25em;
text-align: center;
font-size: 80%;
font-weight: bold;
}
.host a { text-decoration: none; }
pre.code
{
border: #000 dashed 1px;
background: #eee;
padding: 3px 5px;
}
div.left
{
float: left;
width: 20%;
margin: 0 1% 0 5%;
}
div.middle
{
float: left;
width: 60%;
padding: 0 2%;
margin: 0;
border: #000 solid 1px;
min-width: 300px;
}
div.right
{
float: left;
width: 24%;
margin-left: 2%;
}
/* footer */
#ft
{
clear: both;
display: block;
padding: 1em;
margin-left: -5%;
font-size: 80%;
text-align: center;
}
#fad
{
height: 250px; overflow: hidden;
line-height: 120%; font-size: 80%;
}
</style>
</head>
<body>
<div id="projectinfo">
<div class="left">
<h2>Users</h2>
<p><strong><a href="philo.html">Coding Philosophy</a></strong></p>
<p><strong>Data structures</strong></p>
<p><strong><a href="howto.html">How to</a></strong></p>
<p><strong><a href="unicode.html">Handling Unicode</a></strong></p>
<hr/>
<p><strong><a href="http://sourceforge.net/projects/sxmlc/files">Download sxmlc files</a></strong></p>
<p><strong><a href="http://sourceforge.net/projects/sxmlc/">Project detail and discuss</a></strong></p>
<p><strong><a href="http://sourceforge.net/projects/sxmlc/support">Get support</a></strong></p>
</div>
<div class="middle">
<h2>More on data structures</h2>
<p>
You will find most of the inline documentation in comments in header files.<br/>
Comments in C files are mostly to explain how the code is working, not how it should be used.
</p>
<p>
An XML document is a list of XML nodes, described by the <code>XMLNode</code> struct.<br/>
<h4>XML document</h4>
<p>
An XML document is considered as:
<ol>
<li>a file name</li>
<li>a list of <em>nodes</em>.<br/>
<li>the <em>root node</em></li>
</ol>
The root node is given by its index in the <code>nodes</code> array.<br/>
It usually happens that the root index is > 0, typically when XML prolog and comments are given before.
</p>
<p>
<code>XMLDoc</code> struct HAS TO be initialized with <code>XMLDoc_init</code>, and freed with
<code>XMLDoc_free</code>. Calling <code>XMLDoc_init</code> several times without <code>XMLDoc_free</code>
in between can lead to memory leak.
</p>
<h4>XML node</h4>
<p>
An XML node is basically what lies between the '&lt;' and '&gt;' characters. It is composed of:
<ol>
<li><em>tag name</em> that lies right after the <strong>&lt;</strong></li>
<li><em>attributes</em> between the tag name and the <strong>&gt;</strong>:
<ol>
<li>attribute name</li>
<li>= sign</li>
<li>attribute value</li>
</ol>
</li>
<li>potentially a <em>"tag finisher slash"</em> <strong>/</strong> before the <strong>&gt;</strong></li>
<li><em>text</em> (if there is no "tag finisher slash")</li>
</ol>
<code>&lt;tag attribName="attribValue" ...&gt;</code><br/>
</p>
<p>
Therefore, the <code>XMLNode</code> struct has pointers to all of these information,
all of them being transparently allocated by sxmlc.<br/>
</p>
<p>
The <code>tag_type</code> attribute is an internal representation of the type, for the program
to know how to handle the <code>tag</code> attribute.<br/>
Many nodes (e.g. prolog or comments) use the <code>tag</code> attribute to store its content.
Hence, knowing the tag type eases its display:
<ul>
<li>
<code>TAG_FATHER</code> (<code>&lt;mytag&gt;</code>) is a node that will have children.
Nodes read after it will be added as children of this tag.
</li>
<li>
<code>TAG_SELF</code> (<code>&lt;mytag/&gt;</code>) is a "self-contained" node that has no children.
Nodes read after it are siblings of this tag.
</li>
<li>
<code>TAG_END</code> (<code>&lt;/mytag&gt;</code>) is an ending node that closes its father (if tag names matches).
Nodes read after it are siblings of father tag.<br/>
<em>There is no <code>XMLNode</code> associated with this as it is only used internally by the parser.</em>
</li>
<li>
<code>TAG_INSTR</code> (<code>&lt;?text?&gt;</code>) is a node used for prolog and processing instructions.
</li>
<li>
<code>TAG_COMMENT</code> (<code>&lt;!--text--&gt;</code>) is a comment node.
</li>
<li>
<code>TAG_CDATA</code> (<code>&lt;![CDATA[text]]/&gt;</code>) is a CDATA escaped node.
</li>
<li>
<code>TAG_DOCTYPE</code> (<code>&lt;!DOCTYPE text]/&gt;</code>) is a DOCTYPE node.
</li>
<li>
<code>TAG_TEXT</code> (since v4.1.0) is a special node which <code>text</code> field contains the text of its father node.
It is particularly useful when you want to DOM-parse a document and want to keep the text position in the
childrend, instead of merging all text pieces (default behavior before v4.1.0).<br/>
Thanks go to Olgierd Stankiewicz for that improvement! :)
</li>
</ul>
</p>
<p>
The <code>user</code> attribute is where you can put any type of data related to the node (e.g. pointer
to a struct, ...).
</p>
<p>
<code>XMLNode</code> struct HAS TO be initialized with <code>XMLNode_init</code>, and freed with
<code>XMLNode_free</code>. Calling <code>XMLNode_init</code> several times without <code>XMLNode_free</code>
in between can lead to memory leak.
</p>
</div>
<div id="ft">
<p>
<a href="http://sourceforge.net/">
Project Web Hosted by <img src="http://sflogo.sourceforge.net/sflogo.php?group_id=351439&amp;type=16" alt="SourceForge.net" />
</a>
</p>
<p>
&copy;Copyright 1999-2010 -
<a href="http://geek.net" title="Network which provides and promotes Open Source software downloads, development, discussion and news.">
Geeknet</a>, Inc., All Rights Reserved
</p>
<p>
<a href="http://sourceforge.net/about">About</a>
-
<a href="http://sourceforge.net/tos/tos.php">Legal</a>
-
<a href="http://p.sf.net/sourceforge/getsupport">Help</a>
</p>
</div>
</body>
</html>