Ignore:
Timestamp:
Jul 8, 2002, 6:53:23 PM (23 years ago)
Author:
umoeller
Message:

Misc updates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/xml.c

    r186 r187  
    19021902 *
    19031903 *@@added V0.9.14 (2001-08-09) [umoeller]
     1904 *@@changed V0.9.20 (2002-07-06) [umoeller]: added automatic doctype support
    19041905 */
    19051906
     
    19151916    int i = 0;          // return error per default
    19161917
    1917     APIRET  arc = NO_ERROR;
    1918 
    19191918    // store the previous parser because
    19201919    // all the callbacks use the parser pointer
     
    19221921    pDom->pParser = NULL;
    19231922
    1924     if (    (pDom->pfnExternalHandler)
     1923    if (    (    (pDom->pfnExternalHandler)
     1924              || (pDom->cSystemIds)      // V0.9.20 (2002-07-06) [umoeller]
     1925            )
    19251926            // create sub-parser and replace the one
    19261927            // in the DOM with it
     
    19301931       )
    19311932    {
    1932         if ((arc = pDom->pfnExternalHandler(pDom,
    1933                                             pDom->pParser,
    1934                                             pcszSystemId,
    1935                                             pcszPublicId)))
    1936         {
    1937             // error:
    1938             // now this needs special handling, since we're
    1939             // dealing with a sub-handler here...
    1940 
    1941             if (arc == -1)
    1942                 // parser error: well, then xmlSetError has been
    1943                 // called from somewhere in the callbacks already,
    1944                 // and we can safely ignore this
    1945                 ;
     1933        // run through the predefined doctypes given to us
     1934        // in xmlCreateDOM, if any
     1935        // V0.9.20 (2002-07-06) [umoeller]
     1936        BOOL fCallExternal = TRUE;
     1937        ULONG ul;
     1938
     1939        for (ul = 0;
     1940             ul < pDom->cSystemIds;
     1941             ++ul)
     1942        {
     1943            const STATICSYSTEMID *pThis = &pDom->paSystemIds[ul];
     1944            if (!strcmp(pThis->pcszSystemId, pcszSystemId))
     1945            {
     1946                // this one matches:
     1947                // then parse the corresponding entry given
     1948                // to us
     1949                if (XML_Parse(pDom->pParser,
     1950                              pThis->pcszContent,
     1951                              strlen(pThis->pcszContent),
     1952                              TRUE))
     1953                    i = 1;      // success
     1954
     1955                fCallExternal = FALSE;
     1956
     1957                break;
     1958            }
     1959        }
     1960
     1961        if (    (fCallExternal)     // not handled above
     1962             && (pDom->pfnExternalHandler) // user handler set
     1963           )
     1964        {
     1965            APIRET  arc;
     1966
     1967            if (!(arc = pDom->pfnExternalHandler(pDom,
     1968                                                 pDom->pParser,
     1969                                                 pcszSystemId,
     1970                                                 pcszPublicId)))
     1971                i = 1;      // success
    19461972            else
    19471973            {
    1948                 pDom->arcDOM = arc;
    1949                 if (pcszSystemId)
     1974                // error:
     1975                // now this needs special handling, since we're
     1976                // dealing with a sub-handler here...
     1977
     1978                if (arc == -1)
     1979                    // parser error: well, then xmlSetError has been
     1980                    // called from somewhere in the callbacks already,
     1981                    // and we can safely ignore this
     1982                    ;
     1983                else
    19501984                {
    1951                     if (!pDom->pxstrFailingNode)
    1952                         pDom->pxstrFailingNode = xstrCreate(0);
    1953                     xstrcpy(pDom->pxstrFailingNode, pcszSystemId, 0);
     1985                    pDom->arcDOM = arc;
     1986                    if (pcszSystemId)
     1987                    {
     1988                        if (!pDom->pxstrFailingNode)
     1989                            pDom->pxstrFailingNode = xstrCreate(0);
     1990                        xstrcpy(pDom->pxstrFailingNode, pcszSystemId, 0);
     1991                    }
     1992                    pDom->pcszErrorDescription = xmlDescribeError(arc);
     1993                    pDom->ulErrorLine = XML_GetCurrentLineNumber(pDom->pParser);
     1994                    pDom->ulErrorColumn = XML_GetCurrentColumnNumber(pDom->pParser);
    19541995                }
    1955                 pDom->pcszErrorDescription = xmlDescribeError(arc);
    1956                 pDom->ulErrorLine = XML_GetCurrentLineNumber(pDom->pParser);
    1957                 pDom->ulErrorColumn = XML_GetCurrentColumnNumber(pDom->pParser);
    19581996            }
    19591997        }
    1960 
    1961         i = 1;      // success
    19621998    }
    19631999    else
    19642000        xmlSetError(pDom,
    1965                     (!arc) ? ERROR_DOM_INVALID_EXTERNAL_HANDLER : arc,
     2001                    ERROR_DOM_INVALID_EXTERNAL_HANDLER,
    19662002                    NULL,
    19672003                    FALSE);
     
    23362372 *      not all @expat features are supported yet.
    23372373 *
     2374 *      flParserFlags is any combination of the following:
     2375 *
     2376 *      --  DF_PARSECOMMENTS: XML @comments are to be returned in
     2377 *          the DOM tree. Otherwise they are discarded.
     2378 *
     2379 *      --  DF_PARSEDTD: add the @DTD of the document into the DOM tree
     2380 *          as well and validate the document, if a DTD was found.
     2381 *          Otherwise just parse and do not validate.
     2382 *
     2383 *          DF_PARSEDTD is required for external entities to work
     2384 *          also.
     2385 *
     2386 *      --  DF_FAIL_IF_NO_DTD: fail if no @DTD was found. Useful
     2387 *          if you want to enforce validation. @@todo
     2388 *
     2389 *      --  DF_DROP_WHITESPACE: discard all @whitespace for those
     2390 *          elements that can only have element content. Whitespace
     2391 *          will be preserved only for elements that can have
     2392 *          mixed content. -- If this flag is not set, all whitespace
     2393 *          is preserved.
     2394 *
    23382395 *      The following callbacks can be specified (any of these
    23392396 *      can be NULL):
     
    23712428 *              the int at index 0x94 to 0x00f6.
    23722429 *
    2373  *      pvCallbackUser is a user parameter which is simply stored
    2374  *      in the XMLDOM struct which is returned. Since the XMLDOM
    2375  *      is passed to all the callbacks, you can access that pointer
    2376  *      from them.
    2377  *
    2378  *      flParserFlags is any combination of the following:
    2379  *
    2380  *      --  DF_PARSECOMMENTS: XML @comments are to be returned in
    2381  *          the DOM tree. Otherwise they are discarded.
    2382  *
    2383  *      --  DF_PARSEDTD: add the @DTD of the document into the DOM tree
    2384  *          as well and validate the document, if a DTD was found.
    2385  *          Otherwise just parse and do not validate.
    2386  *
    2387  *          DF_PARSEDTD is required for external entities to work
    2388  *          also.
    2389  *
    2390  *      --  DF_FAIL_IF_NO_DTD: fail if no @DTD was found. Useful
    2391  *          if you want to enforce validation. @@todo
    2392  *
    2393  *      --  DF_DROP_WHITESPACE: discard all @whitespace for those
    2394  *          elements that can only have element content. Whitespace
    2395  *          will be preserved only for elements that can have
    2396  *          mixed content. -- If this flag is not set, all whitespace
    2397  *          is preserved.
     2430 *      --  pvCallbackUser is a user parameter which is simply stored
     2431 *          in the XMLDOM struct which is returned. Since the XMLDOM
     2432 *          is passed to all the callbacks, you can access that pointer
     2433 *          from them.
    23982434 *
    23992435 *@@added V0.9.9 (2001-02-14) [umoeller]
     
    24022438
    24032439APIRET xmlCreateDOM(ULONG flParserFlags,            // in: DF_* parser flags
     2440                    const STATICSYSTEMID *paSystemIds, // in: array of STATICSYSTEMID's or NULL
     2441                    ULONG cSystemIds,                // in: array item count
    24042442                    PFNGETCPDATA pfnGetCPData,      // in: codepage callback or NULL
    24052443                    PFNEXTERNALHANDLER pfnExternalHandler, // in: external entity callback or NULL
     
    24222460        pDom->pfnExternalHandler = pfnExternalHandler;
    24232461        pDom->pvCallbackUser = pvCallbackUser;
     2462
     2463        // these added with V0.9.20 (2002-07-06) [umoeller]
     2464        pDom->paSystemIds = paSystemIds;
     2465        pDom->cSystemIds = cSystemIds;
    24242466
    24252467        lstInit(&pDom->llElementStack,
     
    24702512                                          CommentHandler);
    24712513
    2472                 if (pfnExternalHandler)
     2514                if (    (pfnExternalHandler)
     2515                     || (cSystemIds)     // V0.9.20 (2002-07-06) [umoeller]
     2516                   )
    24732517                    XML_SetExternalEntityRefHandler(pDom->pParser,
    24742518                                                    ExternalEntityRefHandler);
Note: See TracChangeset for help on using the changeset viewer.