[xml] XML Catalog problem



Hi,

I have a libxml2 program that parses a format called NewsML. The NewsML
contains fragments of another format called NITF, and the NITF DTD is declared as an external entity. A minimal example is shown below:

<?xml version="1.0"?>
<!DOCTYPE NewsML SYSTEM "http://www.customer.press.net/resources/NewsMLv1.0.dtd"; [ <!ENTITY % NITF-DTD SYSTEM "http://www.customer.press.net/resources/nitf.dtd";> %NITF-DTD;
]>
<NewsML>
...
  <DataContent>
    <nitf>
      <body>
        <body.head>
          <hedline>Embedded NITF</hedline>
        </body.head>
        <body.content>
          <p>The body text of the embedded NITF.</p>
        </body.content>
      </body>
    </nitf>
  </DataContent>
...
</NewsML>

I have created a catalog file, shown below, and set the environment variable XML_CATALOG_FILES to point to it:

<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd";>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<system systemId="http://www.customer.press.net/resources/NewsMLv1.0.dtd"; uri="file:///home/chris/newsml.dtd"/> <system systemId="http://www.customer.press.net/resources/nitf.dtd"; uri="file:///home/chris/nitf.dtd"/>
</catalog>

I then try and parse a NewsML file using the following fragment of code:

int
newsmlparser_set_xml(NewsMLParser *parser, const char *xml)
{
    xmlValidCtxt valid_ctxt;

    parser->doc = xmlParseFile(xml);

    if (parser->doc == NULL) {
        parser->status = NEWSMLPARSER_MALFORMED_XML;
        return 1;
    }

    memset(&valid_ctxt, 0, sizeof(valid_ctxt));

    if (xmlValidateDocument(&valid_ctxt, parser->doc) == 0) {
        parser->status = NEWSMLPARSER_MALFORMED_XML;
        return 1;
    }

    return 0;
}

This fails, with a message from libxml2 saying that it cannot resolve the NITF DTD as an external entity. I have compiled libxml2 without HTTP or FTP support, as my program will run on a machine that is not connected to a network.

Resolve: sysID http://www.customer.press.net/resources/nitf.dtd
Failed to parse catalog file:///etc/xml/catalog
Resolve URI http://www.customer.press.net/resources/nitf.dtd
test.xml:3: I/O warning : failed to load external entity "http://www.customer.press.net/resources/nitf.dtd";
        %NITF-DTD;
                  ^
 %NITF-DTD;
           ^
Resolve: sysID http://www.customer.press.net/resources/NewsMLv1.0.dtd
Resolve URI http://www.customer.press.net/resources/NewsMLv1.0.dtd
I/O warning : failed to load external entity "http://www.customer.press.net/resources/NewsMLv1.0.dtd"; validity error : Could not load the external subset "http://www.customer.press.net/resources/NewsMLv1.0.dtd";

Any suggestions as to why libxml2 is not using
my catalog file would be most appreciated!

Regards,

Chris



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]