Comments (6)
I'm still polishing v4.3.0 but here is what the final XMLNode_insert_child()
will look like, if you want to use it asap:
#define CHECK_NODE(node,ret) if ((node) == NULL || (node)->init_value != XML_INIT_DONE) return (ret)
int XMLNode_insert_child(XMLNode* node, XMLNode* child, int index)
{
int i, j;
CHECK_NODE(node, -1);
/* We could process cases "first" and "last" in an optimized way, but we prefer readability to (micro-)optimization */
if (index < 0) /* Before first => first */
index = 0;
if (index >= node->n_children) /* After last => last */
index = node->n_children - 1;
for (i = 0; i < node->n_children; i++) {
if (!node->children[i]->active || index-- > 0)
continue;
/* Insert it here, at 'i' */
if (_add_node(&node->children, &node->n_children, child) >= 0) {
node->tag_type = TAG_FATHER;
child->father = node;
/* Erase 'child', which is the last node ('n_children' has been incremented by '_add_node()') */
for (j = node->n_children - 1; j >= i; j--)
node->children[j] = node->children[j-1];
node->children[i] = child; /* Set it */
return true;
} else
return false;
}
return false; /* Oops! */
}
from sxmlc.
v4.3.0 pushed.
Some more work is coming regarding documentation (tentative switching to Doxygen) and more thorough unit testing.
from sxmlc.
Wow, this was very fast, and I'll be using it on next days. Thanks!
from sxmlc.
Good idea! I will implement it in the upcoming v4.3.0.
In the meantime, if you want that type of functionality, you should directly manipulate the node->children
array (with XMLNode_add_child()
to allocate space, then move all nodes one by one in a loop):
XMLNode_add_child(node, child);
memmove(node->children[i+1], node->children[i], node->n_children - i - 1);
node->children[i] = child;
from sxmlc.
This are very good news, and thanks for the explanation on the workaround.
I'll be looking forward for this new version! In the meantime, I'll make use of the workaround. Cheers!
from sxmlc.
This is great Matthieu, I'll be using this code these days. I'll be looking forward for 4.3.0.
from sxmlc.
Related Issues (17)
- Getting non-expected values after compiling for x64 (MinGW) HOT 2
- Free node->text before overwriting it? HOT 3
- Since commit 5cf1ce9 (4.3.1), XML search engine malfunctions HOT 1
- valgrind detects errors in XMLSearch_init HOT 3
- text content is not escaped HOT 5
- Pars data from STRING HOT 21
- search specific data in string .. key --> value HOT 17
- why can't I find all tags.. what can be problem .. HOT 1
- reading from EPROM HOT 4
- Tag by Tag HOT 4
- SEGV in DOMXMLDoc_node_end at sxmlc.c:1600 HOT 1
- SEGV in freadBOM at sxmlc.c:2294 HOT 1
- opening XML from memory buffer or stream HOT 1
- simple xpath not working? HOT 2
- Memory leak in XMLSearch_free() HOT 11
- A few suggestions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sxmlc.