diff --git a/src/topology-xml-libxml.c b/src/topology-xml-libxml.c
index 31081b6..da6a6a9 100644
--- a/src/topology-xml-libxml.c
+++ b/src/topology-xml-libxml.c
@@ -146,10 +146,12 @@ hwloc__libxml_import_get_content(hwloc__xml_import_state_t state,
   size_t length;
 
   child = lstate->node->children;
-  if (!child)
-    return 0;
-  if (child->type != XML_TEXT_NODE)
+  if (!child || child->type != XML_TEXT_NODE) {
+    if (expected_length)
+      return -1;
+    *beginp = "";
     return 0;
+  }
 
   length = strlen((char *) child->content);
   if (length != expected_length)
diff --git a/src/topology-xml-nolibxml.c b/src/topology-xml-nolibxml.c
index 60d63d6..32dadb7 100644
--- a/src/topology-xml-nolibxml.c
+++ b/src/topology-xml-nolibxml.c
@@ -219,8 +219,12 @@ hwloc__nolibxml_import_get_content(hwloc__xml_import_state_t state,
   char *end;
 
   /* auto-closed tags have no content */
-  if (nstate->closed)
+  if (nstate->closed) {
+    if (expected_length)
+      return -1;
+    *beginp = "";
     return 0;
+  }
 
   /* find the next tag, where the content ends */
   end = strchr(buffer, '<');
diff --git a/include/private/xml.h b/include/private/xml.h
index 75c6c43..d7bc02f 100644
--- a/include/private/xml.h
+++ b/include/private/xml.h
@@ -39,7 +39,7 @@ struct hwloc_xml_backend_data_s {
   int (*find_child)(struct hwloc__xml_import_state_s * state, struct hwloc__xml_import_state_s * childstate, char **tagp);
   int (*close_tag)(struct hwloc__xml_import_state_s * state); /* look for an explicit closing tag </name> */
   void (*close_child)(struct hwloc__xml_import_state_s * state);
-  int (*get_content)(struct hwloc__xml_import_state_s * state, char **beginp, size_t expected_length);
+  int (*get_content)(struct hwloc__xml_import_state_s * state, char **beginp, size_t expected_length); /* return 0 on empty content (and sets beginp to empty string), 1 on actual content, -1 on error or unexpected content length */
   void (*close_content)(struct hwloc__xml_import_state_s * state);
   char * msgprefix;
   void *data; /* libxml2 doc, or nolibxml buffer */
