Skip to content

Commit 9fe2cdb

Browse files
author
Matthieu Labas
committed
*** v4.3.0 - Added Github#9: "Support for XMLNode_add_sibling()".
- Documentation update. - Rudimentary unit testing.
1 parent afc5191 commit 9fe2cdb

File tree

8 files changed

+655
-66
lines changed

8 files changed

+655
-66
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
*** v4.3.0 - Added Github#9: "Support for XMLNode_add_sibling()".
2+
- Documentation update.
3+
- Rudimentary unit testing.
4+
15
*** v4.2.7 - Fixed #20 by Richard Minner (SXMLC_VERSION not updated), #21, #22 by George Makarov (sx_f* consistency).
26

37
*** v4.2.6 - Fixed #17, #18, #19 by Andreas Neustifter (infinite loop and compilation messages).

doc/datastruct.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ <h4>XML node</h4>
192192
<li>
193193
<code>TAG_TEXT</code> (since v4.1.0) is a special node which <code>text</code> field contains the text of its father node.
194194
It is particularly useful when you want to DOM-parse a document and want to keep the text position in the
195-
childrend, instead of merging all text pieces (default behavior before v4.1.0).<br/>
195+
children, instead of merging all text pieces (default behavior before v4.1.0).<br/>
196196
Thanks go to Olgierd Stankiewicz for that improvement! :)
197197
</li>
198198
</ul>
@@ -207,6 +207,17 @@ <h4>XML node</h4>
207207
in between can lead to memory leak.
208208
</p>
209209

210+
<h5>Inactive Nodes</h5>
211+
<p>
212+
Nodes can be <em>inactive</em>: they are still in the list of their father node's children, but will <em>not</em> be
213+
displayed by <code>XMLDoc_print()</code> or taken into account by any <code>XMLNode_*()</code> functions!
214+
</p>
215+
<p>
216+
Marking a node "invalid" is equivalent to send it to the trash bin: it will be invisible to every accessor functions.<br/>
217+
If there is a need to access them, it should be done by manipulating the father's children list directly (see more at
218+
<a href="howto.html#INACTIVE">Inactive nodes HOW TO</a>).
219+
</p>
220+
210221
</div>
211222

212223
<div id="ft">

doc/howto.html

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ <h2>How to</h2>
125125
</ul>
126126
</li>
127127
<li><a href="#CUSTOM">Handle new tags</a>
128+
<li><a href="#INACTIVE">Handle inactive nodes</a>
128129
</ul>
129130

130131
<hr/>
@@ -174,9 +175,9 @@ <h5>SAX parser</h5>
174175
There are only 6 callbacks that can be called when using the SAX parser (plus an additional one if needed):
175176
<ul>
176177
<li><code>start_doc</code> is called when document parsing starts, before parsing the first node.</li>
177-
<li><code>start_node</code> is called when a new node has been found (e.g. "<code>&lt;newNode param="val"&gt;</code>")</li>
178+
<li><code>start_node</code> is called when a new node has been found (e.g. "<code>&lt;newNode param="val"&gt;</code>"). <em>All node attributes are already read</em>.</li>
178179
<li><code>end_node</code> is called when a node is being closed. (e.g. "<code>&lt;/newNode&gt;</code>")</li>
179-
<li><code>new_text</code> is called when text has been read from a node(e.g. "<code>&lt;newNode&gt;My text&lt;/newNode&gt;</code>")</li>
180+
<li><code>new_text</code> is called when text has been read from a node(e.g. "<code>&lt;newNode&gt;My text&lt;/newNode&gt;</code>" or "<code>&lt;newNode&gt;My text&lt;OtherNode&gt;...</code>")</li>
180181
<li><code>end_doc</code> is called when document parsing ends. No other callbacks will be called after.</li>
181182
<li><code>on_error</code> is called when an error occurs during parsing. Parsing stops after.</li>
182183
<li><code>all_event</code> is given for those who prefer to handle all such events in a single function instead of three
@@ -297,9 +298,15 @@ <h6>DOM text handling</h6>
297298
<ul>
298299
<li><code>node1.text</code> is <code>NULL</code></li>
299300
<li><code>node1.n_children</code> is 3</li>
300-
<li><code>node1.children[0]->tag_type</code> is <code>TAG_FATHER</code></li>
301-
<li><code>node1.children[0]->text</code> is <code>text1</code></li>
302-
<li><code>node1.children[2]->text</code> is <code>text3</code></li>
301+
<li><code>node1.children[0]</code>:<ul>
302+
<li><code>.tag_type</code> is <code>TAG_TEXT</code></li>
303+
<li><code>.text</code> is <code>text1</code></li></ul></li>
304+
<li><code>node1.children[1]</code>:<ul>
305+
<li><code>.tag_type</code> is <code>TAG_FATHER</code></li>
306+
<li><code>.text</code> is <code>NULL</code></li></ul></li>
307+
<li><code>node1.children[2]</code>:<ul>
308+
<li><code>.tag_type</code> is <code>TAG_TEXT</code></li>
309+
<li><code>.text</code> is <code>text3</code></li></ul></li>
303310
</ul>
304311
The previous behavior is kept if <code>DOM_through_SAX.text_as_nodes</code> is 0 (text concatenation).
305312
</p>
@@ -318,38 +325,22 @@ <h4>Create an XML document</h4>
318325

319326
XMLDoc_init(&doc);
320327

321-
node = XMLNode_alloc();
322-
XMLNode_set_tag(node, "xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"");
323-
XMLNode_set_type(node, TAG_INSTR);
328+
node = XMLNode_new(TAG_INSTR, "xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"", NULL);
324329
XMLDoc_add_node(&doc, node);
325330

326-
node = XMLNode_alloc();
327-
XMLNode_set_tag(node, " Pre-comment ");
328-
XMLNode_set_type(node, TAG_COMMENT);
329-
// Or since v4.3.0: node = XMLNode_new_node_comment(" Pre-comment ");
331+
node = XMLNode_new_node_comment(" Pre-comment ");
330332
XMLDoc_add_node(&doc, node);
331333

332-
node = XMLNode_alloc();
333-
XMLNode_set_tag(node, "\nAnother one\nMulti-line...\n");
334-
XMLNode_set_type(node, TAG_COMMENT);
335-
// Or since v4.3.0: node = XMLNode_new_node_comment("\nAnother one\nMulti-line...\n");
334+
node = XMLNode_new_node_comment("\nAnother one\nMulti-line...\n");
336335
XMLDoc_add_node(&doc, node);
337336

338-
node = XMLNode_alloc();
339-
XMLNode_set_tag(node, "properties");
340-
XMLNode_set_type(node, TAG_FATHER);
337+
node = XMLNode_new(TAG_FATHER, "properties", NULL);
341338
XMLDoc_add_node(&doc, node); // Becomes root node because of 'TAG_FATHER'
342339

343-
node = XMLNode_alloc();
344-
XMLNode_set_type(node, TAG_COMMENT);
345-
XMLNode_set_tag(node, "Hello World!");
346-
// Or since v4.3.0: node = XMLNode_new_node_comment("Hello World!");
340+
node = XMLNode_new_node_comment("Hello World!");
347341
XMLDoc_add_child_root(&doc, node);
348342

349-
node = XMLNode_alloc();
350-
XMLNode_set_tag(node, "info");
351-
XMLNode_set_text(node, "This is my name");
352-
// Or since v4.3.0: node = XMLNode_new_node_text("info", "This is my name");
343+
node = XMLNode_new_node_text("info", "This is my name");
353344
XMLNode_set_attribute(node, "type", "Name");
354345
XMLDoc_add_child_root(&doc, node);
355346
</pre>
@@ -543,6 +534,55 @@ <h4>Handle new tags</h4>
543534
</pre>
544535
</p>
545536

537+
<a name="INACTIVE"/>
538+
<p>
539+
<h4>Handle inactive nodes</h4>
540+
<p>
541+
Nodes marked "inactive" are made invisible by <code>XMLNode_*()</code> accessor functions. So
542+
once a node retrieved by <code>XMLNode_get_child()</code> is marked as inactive, <em>you can no longer
543+
get a reference to it</em>! Instead, you have to manually access their father's children list directly
544+
(which <code>sxmlc</code> lets you do simply, hence its name ;-)).
545+
</p>
546+
<p>
547+
Consider the following XML:
548+
<pre class="code">
549+
&lt;root&gt;
550+
&lt;child0&gt;
551+
&lt;child1&gt;
552+
&lt;child2&gt;
553+
&lt;/root&gt;
554+
</pre>
555+
The following code:
556+
<pre class="code">
557+
XMLNode* node;
558+
559+
node = XMLNode_get_child(father, 0); // Get first ACTIVE child (real index: 0)
560+
XMLNode_print_header(node, stdout, 0, 4);
561+
node->active = false;
562+
563+
node = XMLNode_get_child(father, 0); // Get first ACTIVE child (real index: 1)
564+
XMLNode_print_header(node, stdout, 0, 4);
565+
node->active = false;
566+
567+
node = XMLNode_get_child(father, 0); // Get first ACTIVE child (real index: 2)
568+
XMLNode_print_header(node, stdout, 0, 4);
569+
node->active = false;
570+
571+
father->children[1]->active = true; // Re-activate node [1] by direct access to children list
572+
573+
node = XMLNode_get_child(father, 0); // Get first ACTIVE child (real index: 1)
574+
printf("\n");
575+
XMLNode_print_header(node, stdout, 0, 4);
576+
</pre>
577+
Will print the following:
578+
<pre class="code">
579+
&lt;child0&gt;
580+
&lt;child1&gt;
581+
&lt;child2&gt;
582+
583+
&lt;child1&gt;
584+
</pre>
585+
</p>
546586
</div>
547587

548588
<div id="ft">

src/examples/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ int _allin1(XMLEvent event, const XMLNode* node, SXML_CHAR* text, const int n, S
810810
}
811811
}
812812

813-
#if 1
813+
#if 0
814814
int main()
815815
{
816816
int ret;

0 commit comments

Comments
 (0)