]> xenbits.xensource.com Git - libvirt.git/commitdiff
Use common XML parsing functions
authorJiri Denemark <jdenemar@redhat.com>
Wed, 24 Feb 2010 20:53:16 +0000 (21:53 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 23 Mar 2010 14:40:10 +0000 (15:40 +0100)
src/conf/domain_conf.c
src/conf/interface_conf.c
src/conf/network_conf.c
src/conf/node_device_conf.c
src/conf/secret_conf.c
src/conf/storage_conf.c

index 79c7ea3c66579af52cf81b9e91ef11fdd079a3b5..22e167922687856b753c62cc4f7624f15e0e87c2 100644 (file)
@@ -4168,99 +4168,35 @@ error:
 }
 
 
-/* Called from SAX on parsing errors in the XML. */
-static void
-catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
+static virDomainDefPtr
+virDomainDefParse(const char *xmlStr,
+                  const char *filename,
+                  virCapsPtr caps,
+                  int flags)
 {
-    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-
-    if (ctxt) {
-        if (virGetLastError() == NULL &&
-            ctxt->lastError.level == XML_ERR_FATAL &&
-            ctxt->lastError.message != NULL) {
-            virDomainReportError(VIR_ERR_XML_DETAIL,
-                                 _("at line %d: %s"),
-                                 ctxt->lastError.line,
-                                 ctxt->lastError.message);
-        }
+    xmlDocPtr xml;
+    virDomainDefPtr def = NULL;
+
+    if ((xml = virXMLParse(filename, xmlStr, "domain.xml"))) {
+        def = virDomainDefParseNode(caps, xml, xmlDocGetRootElement(xml), flags);
+        xmlFreeDoc(xml);
     }
+
+    return def;
 }
 
 virDomainDefPtr virDomainDefParseString(virCapsPtr caps,
                                         const char *xmlStr,
                                         int flags)
 {
-    xmlParserCtxtPtr pctxt;
-    xmlDocPtr xml = NULL;
-    xmlNodePtr root;
-    virDomainDefPtr def = NULL;
-
-    /* Set up a parser context so we can catch the details of XML errors. */
-    pctxt = xmlNewParserCtxt ();
-    if (!pctxt || !pctxt->sax)
-        goto cleanup;
-    pctxt->sax->error = catchXMLError;
-
-    xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr, "domain.xml", NULL,
-                          XML_PARSE_NOENT | XML_PARSE_NONET |
-                          XML_PARSE_NOWARNING);
-    if (!xml) {
-        if (virGetLastError() == NULL)
-              virDomainReportError(VIR_ERR_XML_ERROR,
-                                   "%s", _("failed to parse xml document"));
-        goto cleanup;
-    }
-
-    if ((root = xmlDocGetRootElement(xml)) == NULL) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                              "%s", _("missing root element"));
-        goto cleanup;
-    }
-
-    def = virDomainDefParseNode(caps, xml, root, flags);
-
-cleanup:
-    xmlFreeParserCtxt (pctxt);
-    xmlFreeDoc (xml);
-    return def;
+    return virDomainDefParse(xmlStr, NULL, caps, flags);
 }
 
 virDomainDefPtr virDomainDefParseFile(virCapsPtr caps,
-                                      const char *filename, int flags)
+                                      const char *filename,
+                                      int flags)
 {
-    xmlParserCtxtPtr pctxt;
-    xmlDocPtr xml = NULL;
-    xmlNodePtr root;
-    virDomainDefPtr def = NULL;
-
-    /* Set up a parser context so we can catch the details of XML errors. */
-    pctxt = xmlNewParserCtxt ();
-    if (!pctxt || !pctxt->sax)
-        goto cleanup;
-    pctxt->sax->error = catchXMLError;
-
-    xml = xmlCtxtReadFile (pctxt, filename, NULL,
-                           XML_PARSE_NOENT | XML_PARSE_NONET |
-                           XML_PARSE_NOWARNING);
-    if (!xml) {
-        if (virGetLastError() == NULL)
-              virDomainReportError(VIR_ERR_XML_ERROR,
-                                   "%s", _("failed to parse xml document"));
-        goto cleanup;
-    }
-
-    if ((root = xmlDocGetRootElement(xml)) == NULL) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                              "%s", _("missing root element"));
-        goto cleanup;
-    }
-
-    def = virDomainDefParseNode(caps, xml, root, flags);
-
-cleanup:
-    xmlFreeParserCtxt (pctxt);
-    xmlFreeDoc (xml);
-    return def;
+    return virDomainDefParse(NULL, filename, caps, flags);
 }
 
 
@@ -4296,38 +4232,14 @@ cleanup:
 virDomainObjPtr virDomainObjParseFile(virCapsPtr caps,
                                       const char *filename)
 {
-    xmlParserCtxtPtr pctxt;
-    xmlDocPtr xml = NULL;
-    xmlNodePtr root;
+    xmlDocPtr xml;
     virDomainObjPtr obj = NULL;
 
-    /* Set up a parser context so we can catch the details of XML errors. */
-    pctxt = xmlNewParserCtxt ();
-    if (!pctxt || !pctxt->sax)
-        goto cleanup;
-    pctxt->sax->error = catchXMLError;
-
-    xml = xmlCtxtReadFile (pctxt, filename, NULL,
-                           XML_PARSE_NOENT | XML_PARSE_NONET |
-                           XML_PARSE_NOWARNING);
-    if (!xml) {
-        if (virGetLastError() == NULL)
-              virDomainReportError(VIR_ERR_XML_ERROR,
-                                   "%s", _("failed to parse xml document"));
-        goto cleanup;
+    if ((xml = virXMLParseFile(filename))) {
+        obj = virDomainObjParseNode(caps, xml, xmlDocGetRootElement(xml));
+        xmlFreeDoc(xml);
     }
 
-    if ((root = xmlDocGetRootElement(xml)) == NULL) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                              "%s", _("missing root element"));
-        goto cleanup;
-    }
-
-    obj = virDomainObjParseNode(caps, xml, root);
-
-cleanup:
-    xmlFreeParserCtxt (pctxt);
-    xmlFreeDoc (xml);
     return obj;
 }
 
index 30d07100c273502274bdea8716b1fa27f27cc053..920b090e7173c7587e6c7f2814fd4a0b096b8c92 100644 (file)
@@ -851,96 +851,29 @@ cleanup:
     return def;
 }
 
-/* Called from SAX on parsing errors in the XML. */
-static void
-catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
-{
-    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-
-    if (ctxt) {
-        if (virGetLastError() == NULL &&
-            ctxt->lastError.level == XML_ERR_FATAL &&
-            ctxt->lastError.message != NULL) {
-            virInterfaceReportError (VIR_ERR_XML_DETAIL,
-                                     _("at line %d: %s"),
-                                     ctxt->lastError.line,
-                                     ctxt->lastError.message);
-        }
-    }
-}
-
-virInterfaceDefPtr virInterfaceDefParseString(const char *xmlStr)
+static virInterfaceDefPtr
+virInterfaceDefParse(const char *xmlStr,
+                     const char *filename)
 {
-    xmlParserCtxtPtr pctxt;
-    xmlDocPtr xml = NULL;
-    xmlNodePtr root;
+    xmlDocPtr xml;
     virInterfaceDefPtr def = NULL;
 
-    /* Set up a parser context so we can catch the details of XML errors. */
-    pctxt = xmlNewParserCtxt ();
-    if (!pctxt || !pctxt->sax)
-        goto cleanup;
-    pctxt->sax->error = catchXMLError;
-
-    xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr, "interface.xml", NULL,
-                          XML_PARSE_NOENT | XML_PARSE_NONET |
-                          XML_PARSE_NOWARNING);
-    if (!xml) {
-        if (virGetLastError() == NULL)
-            virInterfaceReportError(VIR_ERR_XML_ERROR,
-                                    "%s", _("failed to parse xml document"));
-        goto cleanup;
+    if ((xml = virXMLParse(filename, xmlStr, "interface.xml"))) {
+        def = virInterfaceDefParseNode(xml, xmlDocGetRootElement(xml));
+        xmlFreeDoc(xml);
     }
 
-    if ((root = xmlDocGetRootElement(xml)) == NULL) {
-        virInterfaceReportError(VIR_ERR_INTERNAL_ERROR,
-                              "%s", _("missing root element"));
-        goto cleanup;
-    }
-
-    def = virInterfaceDefParseNode(xml, root);
-
-cleanup:
-    xmlFreeParserCtxt (pctxt);
-    xmlFreeDoc (xml);
     return def;
 }
 
-virInterfaceDefPtr virInterfaceDefParseFile(const char *filename)
+virInterfaceDefPtr virInterfaceDefParseString(const char *xmlStr)
 {
-    xmlParserCtxtPtr pctxt;
-    xmlDocPtr xml = NULL;
-    xmlNodePtr root;
-    virInterfaceDefPtr def = NULL;
-
-    /* Set up a parser context so we can catch the details of XML errors. */
-    pctxt = xmlNewParserCtxt ();
-    if (!pctxt || !pctxt->sax)
-        goto cleanup;
-    pctxt->sax->error = catchXMLError;
-
-    xml = xmlCtxtReadFile (pctxt, filename, NULL,
-                           XML_PARSE_NOENT | XML_PARSE_NONET |
-                           XML_PARSE_NOWARNING);
-    if (!xml) {
-        if (virGetLastError() == NULL)
-            virInterfaceReportError(VIR_ERR_XML_ERROR,
-                                    "%s", _("failed to parse xml document"));
-        goto cleanup;
-    }
-
-    if ((root = xmlDocGetRootElement(xml)) == NULL) {
-        virInterfaceReportError(VIR_ERR_INTERNAL_ERROR,
-                              "%s", _("missing root element"));
-        goto cleanup;
-    }
-
-    def = virInterfaceDefParseNode(xml, root);
+    return virInterfaceDefParse(xmlStr, NULL);
+}
 
-cleanup:
-    xmlFreeParserCtxt (pctxt);
-    xmlFreeDoc (xml);
-    return def;
+virInterfaceDefPtr virInterfaceDefParseFile(const char *filename)
+{
+    return virInterfaceDefParse(NULL, filename);
 }
 
 static int
index 39ebd62f99b88dcd5549c47fd761f73eb1f3bd31..1f3a44c1293a7d2f238cb721cfa31d4641114052 100644 (file)
@@ -504,96 +504,29 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
     return NULL;
 }
 
-/* Called from SAX on parsing errors in the XML. */
-static void
-catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
-{
-    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-
-    if (ctxt) {
-        if (virGetLastError() == NULL &&
-            ctxt->lastError.level == XML_ERR_FATAL &&
-            ctxt->lastError.message != NULL) {
-            virNetworkReportError(VIR_ERR_XML_DETAIL,
-                                  _("at line %d: %s"),
-                                  ctxt->lastError.line,
-                                  ctxt->lastError.message);
-        }
-    }
-}
-
-virNetworkDefPtr virNetworkDefParseString(const char *xmlStr)
+static virNetworkDefPtr
+virNetworkDefParse(const char *xmlStr,
+                   const char *filename)
 {
-    xmlParserCtxtPtr pctxt;
-    xmlDocPtr xml = NULL;
-    xmlNodePtr root;
+    xmlDocPtr xml;
     virNetworkDefPtr def = NULL;
 
-    /* Set up a parser context so we can catch the details of XML errors. */
-    pctxt = xmlNewParserCtxt ();
-    if (!pctxt || !pctxt->sax)
-        goto cleanup;
-    pctxt->sax->error = catchXMLError;
-
-    xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr, "network.xml", NULL,
-                          XML_PARSE_NOENT | XML_PARSE_NONET |
-                          XML_PARSE_NOWARNING);
-    if (!xml) {
-        if (virGetLastError() == NULL)
-            virNetworkReportError(VIR_ERR_XML_ERROR,
-                                  "%s", _("failed to parse xml document"));
-        goto cleanup;
-    }
-
-    if ((root = xmlDocGetRootElement(xml)) == NULL) {
-        virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
-                              "%s", _("missing root element"));
-        goto cleanup;
+    if ((xml = virXMLParse(filename, xmlStr, "network.xml"))) {
+        def = virNetworkDefParseNode(xml, xmlDocGetRootElement(xml));
+        xmlFreeDoc(xml);
     }
 
-    def = virNetworkDefParseNode(xml, root);
-
-cleanup:
-    xmlFreeParserCtxt (pctxt);
-    xmlFreeDoc (xml);
     return def;
 }
 
-virNetworkDefPtr virNetworkDefParseFile(const char *filename)
+virNetworkDefPtr virNetworkDefParseString(const char *xmlStr)
 {
-    xmlParserCtxtPtr pctxt;
-    xmlDocPtr xml = NULL;
-    xmlNodePtr root;
-    virNetworkDefPtr def = NULL;
-
-    /* Set up a parser context so we can catch the details of XML errors. */
-    pctxt = xmlNewParserCtxt ();
-    if (!pctxt || !pctxt->sax)
-        goto cleanup;
-    pctxt->sax->error = catchXMLError;
-
-    xml = xmlCtxtReadFile (pctxt, filename, NULL,
-                           XML_PARSE_NOENT | XML_PARSE_NONET |
-                           XML_PARSE_NOWARNING);
-    if (!xml) {
-        if (virGetLastError() == NULL)
-            virNetworkReportError(VIR_ERR_XML_ERROR,
-                                  "%s", _("failed to parse xml document"));
-        goto cleanup;
-    }
-
-    if ((root = xmlDocGetRootElement(xml)) == NULL) {
-        virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
-                              "%s", _("missing root element"));
-        goto cleanup;
-    }
-
-    def = virNetworkDefParseNode(xml, root);
+    return virNetworkDefParse(xmlStr, NULL);
+}
 
-cleanup:
-    xmlFreeParserCtxt (pctxt);
-    xmlFreeDoc (xml);
-    return def;
+virNetworkDefPtr virNetworkDefParseFile(const char *filename)
+{
+    return virNetworkDefParse(NULL, filename);
 }
 
 
index 09c0f41672a3843c1a3b5c8e81dbb0d2e1c97940..7f2dac80e35edda191af06839ac0a5d397df091c 100644 (file)
@@ -1224,71 +1224,19 @@ cleanup:
     return def;
 }
 
-/* Called from SAX on parsing errors in the XML. */
-static void
-catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
-{
-    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-
-    if (ctxt) {
-        if (virGetLastError() == NULL &&
-            ctxt->lastError.level == XML_ERR_FATAL &&
-            ctxt->lastError.message != NULL) {
-            virNodeDeviceReportError(VIR_ERR_XML_DETAIL,
-                                     _("at line %d: %s"),
-                                     ctxt->lastError.line,
-                                     ctxt->lastError.message);
-        }
-    }
-}
-
-
-
 static virNodeDeviceDefPtr
 virNodeDeviceDefParse(const char *str,
                       const char *filename,
                       int create)
 {
-    xmlParserCtxtPtr pctxt;
-    xmlDocPtr xml = NULL;
-    xmlNodePtr root;
+    xmlDocPtr xml;
     virNodeDeviceDefPtr def = NULL;
 
-    /* Set up a parser context so we can catch the details of XML errors. */
-    pctxt = xmlNewParserCtxt ();
-    if (!pctxt || !pctxt->sax)
-        goto cleanup;
-    pctxt->sax->error = catchXMLError;
-
-    if (filename) {
-        xml = xmlCtxtReadFile (pctxt, filename, NULL,
-                               XML_PARSE_NOENT | XML_PARSE_NONET |
-                               XML_PARSE_NOWARNING);
-    } else {
-        xml = xmlCtxtReadDoc (pctxt, BAD_CAST str,
-                              "device.xml", NULL,
-                              XML_PARSE_NOENT | XML_PARSE_NONET |
-                              XML_PARSE_NOWARNING);
+    if ((xml = virXMLParse(filename, str, "device.xml"))) {
+        def = virNodeDeviceDefParseNode(xml, xmlDocGetRootElement(xml), create);
+        xmlFreeDoc(xml);
     }
 
-    if (!xml) {
-        if (virGetLastError() == NULL)
-            virNodeDeviceReportError(VIR_ERR_XML_ERROR,
-                                     "%s", _("failed to parse xml document"));
-        goto cleanup;
-    }
-
-    if ((root = xmlDocGetRootElement(xml)) == NULL) {
-        virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR,
-                                 "%s", _("missing root element"));
-        goto cleanup;
-    }
-
-    def = virNodeDeviceDefParseNode(xml, root, create);
-
-cleanup:
-    xmlFreeParserCtxt(pctxt);
-    xmlFreeDoc(xml);
     return def;
 }
 
index 946d425ccfa812319d5c1da9795f12a9f2a849f8..bbdad89a7e71a0bde738cc497d07600a15b8903c 100644 (file)
@@ -187,62 +187,18 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
     return ret;
 }
 
-/* Called from SAX on parsing errors in the XML. */
-static void
-catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
-{
-    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-
-    if (ctxt) {
-        if (virGetLastError() == NULL &&
-            ctxt->lastError.level == XML_ERR_FATAL &&
-            ctxt->lastError.message != NULL) {
-            virSecretReportError(VIR_ERR_XML_DETAIL, _("at line %d: %s"),
-                                 ctxt->lastError.line, ctxt->lastError.message);
-        }
-    }
-}
-
 static virSecretDefPtr
-virSecretDefParse(const char *xmlStr, const char *filename)
+virSecretDefParse(const char *xmlStr,
+                  const char *filename)
 {
-    xmlParserCtxtPtr pctxt;
-    xmlDocPtr xml = NULL;
-    xmlNodePtr root;
+    xmlDocPtr xml;
     virSecretDefPtr ret = NULL;
 
-    pctxt = xmlNewParserCtxt();
-    if (pctxt == NULL || pctxt->sax == NULL)
-        goto cleanup;
-    pctxt->sax->error = catchXMLError;
-
-    if (filename != NULL)
-        xml = xmlCtxtReadFile(pctxt, filename, NULL,
-                              XML_PARSE_NOENT | XML_PARSE_NONET |
-                              XML_PARSE_NOWARNING);
-    else
-        xml = xmlCtxtReadDoc(pctxt, BAD_CAST xmlStr, "secret.xml", NULL,
-                             XML_PARSE_NOENT | XML_PARSE_NONET |
-                             XML_PARSE_NOWARNING);
-    if (xml == NULL) {
-        if (virGetLastError() == NULL)
-            virSecretReportError(VIR_ERR_XML_ERROR, "%s",
-                                 _("failed to parse xml document"));
-        goto cleanup;
-    }
-
-    root = xmlDocGetRootElement(xml);
-    if (root == NULL) {
-        virSecretReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                             _("missing root element"));
-        goto cleanup;
+    if ((xml = virXMLParse(filename, xmlStr, "secret.xml"))) {
+        ret = secretXMLParseNode(xml, xmlDocGetRootElement(xml));
+        xmlFreeDoc(xml);
     }
 
-    ret = secretXMLParseNode(xml, root);
-
- cleanup:
-    xmlFreeDoc(xml);
-    xmlFreeParserCtxt(pctxt);
     return ret;
 }
 
index 3e37d5fb82673cd98faaec05cc785c50bb9a997e..620744f216270d15ea697e79f61f0094da063fb2 100644 (file)
@@ -717,24 +717,6 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) {
     return NULL;
 }
 
-/* Called from SAX on parsing errors in the XML. */
-static void
-catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
-{
-    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-
-    if (ctxt) {
-        if (virGetLastError() == NULL &&
-            ctxt->lastError.level == XML_ERR_FATAL &&
-            ctxt->lastError.message != NULL) {
-            virStorageReportError (VIR_ERR_XML_DETAIL,
-                                   _("at line %d: %s"),
-                                   ctxt->lastError.line,
-                                   ctxt->lastError.message);
-        }
-    }
-}
-
 virStoragePoolDefPtr
 virStoragePoolDefParseNode(xmlDocPtr xml,
                            xmlNodePtr root) {
@@ -764,52 +746,14 @@ static virStoragePoolDefPtr
 virStoragePoolDefParse(const char *xmlStr,
                        const char *filename) {
     virStoragePoolDefPtr ret = NULL;
-    xmlParserCtxtPtr pctxt;
-    xmlDocPtr xml = NULL;
-    xmlNodePtr node = NULL;
+    xmlDocPtr xml;
 
-    /* Set up a parser context so we can catch the details of XML errors. */
-    pctxt = xmlNewParserCtxt ();
-    if (!pctxt || !pctxt->sax)
-        goto cleanup;
-    pctxt->sax->error = catchXMLError;
-
-    if (filename) {
-        xml = xmlCtxtReadFile (pctxt, filename, NULL,
-                               XML_PARSE_NOENT | XML_PARSE_NONET |
-                               XML_PARSE_NOWARNING);
-    } else {
-        xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr,
-                              "storage.xml", NULL,
-                              XML_PARSE_NOENT | XML_PARSE_NONET |
-                              XML_PARSE_NOWARNING);
+    if ((xml = virXMLParse(filename, xmlStr, "storage.xml"))) {
+        ret = virStoragePoolDefParseNode(xml, xmlDocGetRootElement(xml));
+        xmlFreeDoc(xml);
     }
 
-    if (!xml) {
-        if (virGetLastError() == NULL)
-            virStorageReportError(VIR_ERR_XML_ERROR,
-                                  "%s",_("failed to parse xml document"));
-        goto cleanup;
-    }
-
-    node = xmlDocGetRootElement(xml);
-    if (node == NULL) {
-        virStorageReportError(VIR_ERR_XML_ERROR,
-                              "%s", _("missing root element"));
-        goto cleanup;
-    }
-
-    ret = virStoragePoolDefParseNode(xml, node);
-
-    xmlFreeParserCtxt (pctxt);
-    xmlFreeDoc(xml);
-
     return ret;
-
- cleanup:
-    xmlFreeParserCtxt (pctxt);
-    xmlFreeDoc(xml);
-    return NULL;
 }
 
 virStoragePoolDefPtr
@@ -1163,52 +1107,14 @@ virStorageVolDefParse(virStoragePoolDefPtr pool,
                       const char *xmlStr,
                       const char *filename) {
     virStorageVolDefPtr ret = NULL;
-    xmlParserCtxtPtr pctxt;
-    xmlDocPtr xml = NULL;
-    xmlNodePtr node = NULL;
-
-    /* Set up a parser context so we can catch the details of XML errors. */
-    pctxt = xmlNewParserCtxt ();
-    if (!pctxt || !pctxt->sax)
-        goto cleanup;
-    pctxt->sax->error = catchXMLError;
-
-    if (filename) {
-        xml = xmlCtxtReadFile (pctxt, filename, NULL,
-                               XML_PARSE_NOENT | XML_PARSE_NONET |
-                               XML_PARSE_NOWARNING);
-    } else {
-        xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr,
-                              "storage.xml", NULL,
-                              XML_PARSE_NOENT | XML_PARSE_NONET |
-                              XML_PARSE_NOWARNING);
-    }
-
-    if (!xml) {
-        if (virGetLastError() == NULL)
-            virStorageReportError(VIR_ERR_XML_ERROR,
-                                  "%s", _("failed to parse xml document"));
-        goto cleanup;
-    }
+    xmlDocPtr xml;
 
-    node = xmlDocGetRootElement(xml);
-    if (node == NULL) {
-        virStorageReportError(VIR_ERR_XML_ERROR,
-                              "%s", _("missing root element"));
-        goto cleanup;
+    if ((xml = virXMLParse(filename, xmlStr, "storage.xml"))) {
+        ret = virStorageVolDefParseNode(pool, xml, xmlDocGetRootElement(xml));
+        xmlFreeDoc(xml);
     }
 
-    ret = virStorageVolDefParseNode(pool, xml, node);
-
-    xmlFreeParserCtxt (pctxt);
-    xmlFreeDoc(xml);
-
     return ret;
-
- cleanup:
-    xmlFreeParserCtxt (pctxt);
-    xmlFreeDoc(xml);
-    return NULL;
 }
 
 virStorageVolDefPtr