text.xml TxmlNode.setContent() appends content instead of replacing

Started by TomToad, December 08, 2024, 02:33:44

Previous topic - Next topic

TomToad

Looking a bit more into the source, there seems to be several problems.  Obviously, mxml was intended for simple xml files with elements having either child elements or text, but not both.  So the xml specification is not fully implemented.  It should work fine for 99% of cases, even in the project I am working on as mixing text and child elements don't occur often.

As for the bug that MidiMaster has found, the content is actually replaced.  The new content is given the type MXML_TEXT.  unfortunately, the .getContent() method returns only content with type MXML_OPAQUE.  That's why the replaced content doesn't show up in his example.  Definitely a bug as .getContent() should return  whatever content is there.

Anyway, at least I got the append vs replace bug fixed so I can continue on with my project. :)
------------------------------------------------
8 rabbits equals 1 rabbyte.

Derron

Yes, mxml was introduced because of being a bit more "lightweight" than libxml ... so for most cases mxml will absolutely do.

Mixed content nodes in mxml should still be handleable (will try to do some things and then reply in midimasters issue/bug report).

mxml.mod is already "separated" from xml.mod - so maybe the old libxml module will be brought over as alternative ... dunno. The issue there is then the "lowest common denominator" - or in other words you need to use "libxml.mod" directly then if you want to do things only the module offers but not mxml.mod.


bye
Ron

Derron

@TomToad I posted some code in Midimasters github issue.

With it I was able to replace content of a node in various manners (first text, all text, all content). I am no C expert so I might have done things wrong - and surely there are cases in which it won't work.

I posted also some testCode() function there ... maybe we could extend that (if needed) to be able to retrieve something like getcontent in a "different" manner.


bye
Ron

Midimaster

Brucey did another update and now it looks like working as expected. My example works now, the texts are replaced immediately.

He made only changes in the file glue.c

So you only need to download this:
https://github.com/bmx-ng/text.mod/blob/master/xml.mod/glue.c

and replace your glue.c in your BlitzMax-folder....

...BlitzMax\mod\text.mod\xml.mod\...

...with the new one.

Don't forget to rebuild this module before you use the new version.




...back from North Pole.

Derron

My solution offers more versatility (and could surely be extended to what Brucey did - also replacing specific other things like numbers, string nodes, ...).

The original "issue" imo was that the content was set to "text" instead of "opaque" and the content getter only reading "opaque" things. This way things "replaced, xml-to-string" appeared while the examples directly doing a "node.GetContent()" did not display it.


bye
Ron