DLR-SC / tixi

A simple XML interface library
Apache License 2.0
35 stars 17 forks source link

Feature discussion: export/import element to/from string #202

Closed melven closed 2 years ago

melven commented 2 years ago

Hi,

we have some problems with elements that contain comments. In particular, I currently see no way to generate an element that has text and comments like this:

<root>
  <elem>
    some text
    <!-- some comment -->
    some further text
  </elem>
</root>

The function tixiGetTextElement returns the text without comments (which is a reasonable behavior that we also need).

But for a user of our GUI, it would be nice to actually edit the text together with possible comments.

So one generic idea would be to provide the following two (generic) functions that could also be handy in other cases:

ReturnCode tixiExportElementAsString (const TixiDocumentHandle handle, const char* elementPath, char **text);
ReturnCode tixiImportElementFromString(const TixiDocumentHandle handle, const char* parentPath, const char* elementName, const char* xmlImportString);

tixiExportElementAsString is like tixiExportDocumentAsString but only handles the subtree below the given element.

tixiImportElementFromString behaves similar to tixiCreateElement but the complete content/subtree below the created element is given as "raw" xml string.

Implementation would be similar to the handling of external data nodes but it just allows very powerful "raw" manipulation of XML subtrees...

What do you think?

melven commented 2 years ago

Based on this idea, I implemented #204 and #205.

Only difference from the example here: the element name for tixiImportElementFromString is not supplied as argument but is defined in the XML string itself (the top level element name).

joergbrech commented 2 years ago

I like the suggestion! Thanks for your PRs!