Open GWRon opened 5 years ago
If I understood SetContent
and AddContent
right then the first removes all text elements from a node first and adds the content afterwards while the second just adds the content. Both call mxmlNewText
.
The function mxmlNewText()
in mxml-node.c is just adding a new text node to the parental node and then sets the text/value of this text element - but it does not seem to update the content of the parental node.
The GetContent()
method utilizes mxmlGetOpaque
which returns the node's value (not the one of text elements added to it).
The content was refreshed when not using mxmlNewText
but mxmlNewOpaque
:
glue.c
//OLD
void bmx_mxmlSetContent(mxml_node_t * node, BBString * content) {
mxml_node_t * child = mxmlGetFirstChild(node);
while (child != NULL) {
mxml_node_t * txt = NULL;
if (mxmlGetType(child) == MXML_TEXT) {
txt = child;
}
child = mxmlGetNextSibling(child);
if (txt) {
mxmlDelete(txt);
}
}
char * c = bbStringToUTF8String(content);
mxmlNewText(node, 0, c);
bbMemFree(c);
}
//NEW
void bmx_mxmlSetContent(mxml_node_t * node, BBString * content) {
mxml_node_t * child = mxmlGetFirstChild(node);
while (child != NULL) {
mxml_node_t * txt = NULL;
txt = child;
child = mxmlGetNextSibling(child);
mxmlDelete(txt);
}
char * c = bbStringToUTF8String(content);
mxmlNewOpaque(node, c);
bbMemFree(c);
}
//OLD
void bmx_mxmlAddContent(mxml_node_t * node, BBString * content) {
char * c = bbStringToUTF8String(content);
mxmlNewText(node, 0, c);
bbMemFree(c);
}
//NEW
void bmx_mxmlAddContent(mxml_node_t * node, BBString * content) {
char * c = bbStringToUTF8String(content);
mxmlNewOpaque(node, c);
bbMemFree(c);
}
But I am not sure yet what impact such a change would have to other functionality.
The "NEW" SetContent()
removes any child node for now (limiting to opaque and text nodes only somehow missed the previous "text node" or whatever contained the previous textual content of that node).
When using
node.GetContent()
afternode.SetContent("test")
the result is what was set as content on node creation (so eg when parsing an XML file).Adjusted sample (doc/txmldoc_savefile.bmx):
output:
As you see the
GetContent()
call returns the initial value (an empty string) while the final output contains the freshly set content.