Skip to content

Commit

Permalink
Merge pull request #210 from melven/importElement_invalidateXPathCache
Browse files Browse the repository at this point in the history
Invalidate XPath cache in tixiImportElementFromString
  • Loading branch information
joergbrech authored Apr 7, 2022
2 parents b722874 + 87e42ee commit b7e4e0c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/tixiImpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3204,6 +3204,10 @@ DLL_EXPORT ReturnCode tixiImportElementFromString (const TixiDocumentHandle hand
parseErrors = xmlParseInNodeContext(parentElement, xmlImportString, strlen(xmlImportString), 0, &newElement);

if (!parseErrors) {

// structure change!, we have to empty the xpath cache
XPathClearCache(document->xpathCache);

xmlAddChild(parentElement, newElement);
}
else {
Expand Down
17 changes: 17 additions & 0 deletions tests/import_element_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,20 @@ TEST_F(ImportElementsCheck, notWellFormed)
ASSERT_EQ(NOT_WELL_FORMED, tixiImportElementFromString(handle, "/root/a", "sdaf<||/sdfasf>"));
}

TEST_F(ImportElementsCheck, invalidateXPathCache)
{
char* text = NULL;
int num = 0;
char* path = NULL;

ASSERT_TRUE( tixiSetCacheEnabled(handle, true) == SUCCESS );

ASSERT_TRUE( tixiXPathEvaluateNodeNumber(handle, "//*", &num) == SUCCESS );
ASSERT_EQ(3, num);

ASSERT_EQ(SUCCESS, tixiImportElementFromString(handle, "/root", "<a attr=\"hello\"><x/></a>"));

ASSERT_TRUE( tixiXPathEvaluateNodeNumber(handle, "//*", &num) == SUCCESS );
ASSERT_EQ(5, num);
}

0 comments on commit b7e4e0c

Please sign in to comment.