include/tools/XPath.hxx         |    8 ++++++++
 tools/qa/cppunit/test_xpath.cxx |   10 +++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

New commits:
commit 27f37a1867e1ab0bbeaef07920e605750960e304
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Tue Dec 23 13:05:14 2025 +0900
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Mon Feb 23 13:03:23 2026 +0100

    tools: destroy objects in the correct order in XPathTest
    
    Use xmlDocUniquePtr in XPathTest instead of manually handling the
    pointers and deleting it with xmlFreeDoc function at the end. This
    causes that the objects are not deleted in the correct order.
    
    Change-Id: I9933dc3f354c1374a2e53c9f65ff98b5e6a443c6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196144
    Reviewed-by: Tomaž Vajngerl <[email protected]>
    Tested-by: Jenkins
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200020
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/tools/qa/cppunit/test_xpath.cxx b/tools/qa/cppunit/test_xpath.cxx
index 3cbc29c90ff8..03726b2dc869 100644
--- a/tools/qa/cppunit/test_xpath.cxx
+++ b/tools/qa/cppunit/test_xpath.cxx
@@ -10,6 +10,7 @@
 #include <cppunit/extensions/HelperMacros.h>
 #include <test/bootstrapfixture.hxx>
 #include <rtl/ustring.hxx>
+#include <test/xmldocptr.hxx>
 #include <tools/stream.hxx>
 #include <tools/XPath.hxx>
 
@@ -36,10 +37,11 @@ public:
         pBuffer[nSize] = 0;
         aFileStream.ReadBytes(pBuffer.get(), nSize);
         auto pCharBuffer = reinterpret_cast<xmlChar*>(pBuffer.get());
-        xmlDocPtr pXmlDoc
-            = xmlReadDoc(pCharBuffer, nullptr, nullptr, XML_PARSE_NODICT | 
XML_PARSE_HUGE);
 
-        tools::XPath aXPath(pXmlDoc);
+        xmlDocUniquePtr pXmlDoc(
+            xmlReadDoc(pCharBuffer, nullptr, nullptr, XML_PARSE_NODICT | 
XML_PARSE_HUGE));
+
+        tools::XPath aXPath(pXmlDoc.get());
         auto aNonExistentPath = aXPath.create("/nonexistent");
         CPPUNIT_ASSERT(aNonExistentPath);
         CPPUNIT_ASSERT_EQUAL(0, aNonExistentPath->count());
@@ -80,8 +82,6 @@ public:
         CPPUNIT_ASSERT_EQUAL(u"Content"_ustr, aGrandChildResult->content());
         CPPUNIT_ASSERT_EQUAL(u"ABC"_ustr, 
aGrandChildResult->attribute("attribute1"));
         CPPUNIT_ASSERT_EQUAL(u"CDE"_ustr, 
aGrandChildResult->attribute("attribute2"));
-
-        xmlFreeDoc(pXmlDoc);
     }
 
     CPPUNIT_TEST_SUITE(XPathTest);
commit 42187918270b5a85011887915d766e5adbbae628
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Mon Dec 22 18:38:01 2025 +0900
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Mon Feb 23 13:03:15 2026 +0100

    tools: document XPath classes
    
    Change-Id: I1a06c04e5339fa379bd2a6933f88e430c6cc89f8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196079
    Reviewed-by: Tomaž Vajngerl <[email protected]>
    Tested-by: Jenkins
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200019
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/include/tools/XPath.hxx b/include/tools/XPath.hxx
index 28b7d30ba1ef..398c8d3f1f80 100644
--- a/include/tools/XPath.hxx
+++ b/include/tools/XPath.hxx
@@ -23,6 +23,7 @@
 
 namespace tools
 {
+/** Represents an XML element and allows getting attributes, content, child 
elements. */
 class TOOLS_DLLPUBLIC XmlElement final
 {
     xmlNodePtr mpXmlNode;
@@ -39,6 +40,12 @@ public:
     std::unique_ptr<XmlElement> at(sal_Int32 nIndex);
 };
 
+/** XPath object is a result of XPath evaluation.
+ *
+ * It contains the path string and allows to check the attributes,
+ * content of the result element (if there is only one) or iterates
+ * the resulting elements.
+ */
 class TOOLS_DLLPUBLIC XPathObject final
 {
     xmlXPathObjectPtr mpXPathObject;
@@ -54,6 +61,7 @@ public:
     std::unique_ptr<XmlElement> at(sal_Int32 nIndex);
 };
 
+/** Object that allows to evaluate XPath strings on a XML document. */
 class TOOLS_DLLPUBLIC XPath final
 {
     xmlDocPtr mpXmlDocPtr;

Reply via email to