DLR-SC/tixi

Feature discussion: export/import element to/from string

melven opened this issue · 2 comments

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?

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).

I like the suggestion! Thanks for your PRs!