Changeset 249 for trunk/src/helpers/xml.c
- Timestamp:
- Feb 8, 2003, 9:57:38 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/xml.c
r238 r249 714 714 * 715 715 *@@added V0.9.9 (2001-02-14) [umoeller] 716 *@@changed V1.0.2 (2003-02-07) [umoeller]: added lenValue param 716 717 */ 717 718 … … 719 720 const char *pcszName, // in: attribute name (null-terminated) 720 721 const char *pcszValue, // in: attribute value (null-terminated) 722 ULONG lenValue, // in: length of value (must be specified) 721 723 PDOMNODE *ppNew) 722 724 { 723 APIRET arc = NO_ERROR; 725 APIRET arc; 726 PDOMNODE pNew = NULL; 724 727 725 728 if ( (!pElement) 726 729 || (pElement->NodeBase.ulNodeType != DOMNODE_ELEMENT) 727 730 ) 728 arc = ERROR_DOM_NO_ELEMENT; 729 else 730 { 731 PDOMNODE pNew = NULL; 732 if (!(arc = xmlCreateDomNode(pElement, // this takes care of adding to the list 733 DOMNODE_ATTRIBUTE, 734 pcszName, 735 0, 736 &pNew))) 737 { 738 pNew->pstrNodeValue = xstrCreate(0); 739 xstrcpy(pNew->pstrNodeValue, pcszValue, 0); 740 741 *ppNew = pNew; 742 } 731 return ERROR_DOM_NO_ELEMENT; 732 733 if (!(arc = xmlCreateDomNode(pElement, // this takes care of adding to the list 734 DOMNODE_ATTRIBUTE, 735 pcszName, 736 0, 737 &pNew))) 738 { 739 pNew->pstrNodeValue = xstrCreate(lenValue + 1); 740 xstrcpy(pNew->pstrNodeValue, pcszValue, lenValue); 741 742 *ppNew = pNew; 743 743 } 744 744 … … 759 759 APIRET xmlCreateTextNode(PDOMNODE pParent, // in: parent element node 760 760 const char *pcszText, // in: ptr to start of text 761 ULONG ulLength,// in: length of *pcszText761 ULONG lenText, // in: length of *pcszText 762 762 PDOMNODE *ppNew) 763 763 { … … 772 772 { 773 773 PSZ pszNodeValue; 774 if (pszNodeValue = (PSZ)malloc( ulLength+ 1))774 if (pszNodeValue = (PSZ)malloc(lenText + 1)) 775 775 { 776 memcpy(pszNodeValue, pcszText, ulLength);777 pszNodeValue[ ulLength] = '\0';776 memcpy(pszNodeValue, pcszText, lenText); 777 pszNodeValue[lenText] = '\0'; 778 778 pNew->pstrNodeValue = xstrCreate(0); 779 779 xstrset(pNew->pstrNodeValue, pszNodeValue); … … 1552 1552 { 1553 1553 PDOMNODE pAttrib; 1554 PCSZ pcszValue = papcszAttribs[i + 1]; // attr value 1554 1555 if (!(pDom->arcDOM = xmlCreateAttributeNode(pNew, // element, 1555 1556 papcszAttribs[i], // attr name 1556 papcszAttribs[i + 1], // attr value 1557 pcszValue, 1558 strlen(pcszValue), 1557 1559 &pAttrib))) 1558 1560 { … … 2428 2430 * the int at index 0x94 to 0x00f6. 2429 2431 * 2432 * -- pfnExternalHandler should be specified if you want the 2433 * parser to be able to handle @external_entities. Since 2434 * the parser has no concept of storage whatsoever, it is 2435 * the responsibility of this callback to supply the parser 2436 * with additional XML data when an external entity reference 2437 * is encountered. 2438 * 2439 * This callback must have the following prototype: 2440 * 2441 + APIRET APIENTRY ParseExternal(PXMLDOM pDom, 2442 + XML_Parser pSubParser, 2443 + const char *pcszSystemID, 2444 + const char *pcszPublicID) 2445 + 2446 * 2447 * The callback will be called for each reference that refers 2448 * to an external entity. pSubParser is a sub-parser created 2449 * by the DOM engine, and pcszSystemID and pcszPublicID 2450 * reference the external entity by means of a URI. As always 2451 * with XML, the system ID is required, while the public ID is 2452 * optional. 2453 * 2454 * In the simplest case, this code could look as follows: 2455 * 2456 + APIRET arc = ERROR_FILE_NOT_FOUND; 2457 + 2458 + if (pcszSystemID) 2459 + { 2460 + PSZ pszContents = NULL; 2461 + if (!(arc = doshLoadTextFile(pcszSystemID, 2462 + &pszContents, 2463 + NULL))) 2464 + { 2465 + if (!XML_Parse(pSubParser, 2466 + pszContents, 2467 + strlen(pszContents), 2468 + TRUE)) 2469 + arc = -1; 2470 + 2471 + free(pszContents); 2472 + } 2473 + } 2474 + 2475 + return arc; 2476 * 2430 2477 * -- pvCallbackUser is a user parameter which is simply stored 2431 2478 * in the XMLDOM struct which is returned. Since the XMLDOM … … 2435 2482 *@@added V0.9.9 (2001-02-14) [umoeller] 2436 2483 *@@changed V0.9.14 (2001-08-09) [umoeller]: added DF_DROP_WHITESPACE support 2484 *@@changed V0.9.20 (2002-07-06) [umoeller]: added static system IDs 2437 2485 */ 2438 2486 … … 2445 2493 PXMLDOM *ppDom) // out: XMLDOM struct created 2446 2494 { 2447 APIRET arc = NO_ERROR; 2448 2449 PXMLDOM pDom = (PXMLDOM)malloc(sizeof(*pDom)); 2450 if (!pDom) 2451 arc = ERROR_NOT_ENOUGH_MEMORY; 2452 else 2453 { 2454 PDOMNODE pDocument = NULL; 2455 2456 memset(pDom, 0, sizeof(XMLDOM)); 2457 2458 pDom->flParserFlags = flParserFlags; 2459 pDom->pfnGetCPData = pfnGetCPData; 2460 pDom->pfnExternalHandler = pfnExternalHandler; 2461 pDom->pvCallbackUser = pvCallbackUser; 2462 2463 // these added with V0.9.20 (2002-07-06) [umoeller] 2464 pDom->paSystemIds = paSystemIds; 2465 pDom->cSystemIds = cSystemIds; 2466 2467 lstInit(&pDom->llElementStack, 2468 TRUE); // auto-free 2469 2470 // create the document node 2471 if (!(arc = xmlCreateDomNode(NULL, // no parent 2472 DOMNODE_DOCUMENT, 2473 NULL, 2474 0, 2475 &pDocument))) 2495 APIRET arc = NO_ERROR; 2496 PXMLDOM pDom; 2497 PDOMNODE pDocument = NULL; 2498 2499 if (!(pDom = (PXMLDOM)malloc(sizeof(*pDom)))) 2500 return ERROR_NOT_ENOUGH_MEMORY; 2501 2502 memset(pDom, 0, sizeof(XMLDOM)); 2503 2504 pDom->flParserFlags = flParserFlags; 2505 pDom->pfnGetCPData = pfnGetCPData; 2506 pDom->pfnExternalHandler = pfnExternalHandler; 2507 pDom->pvCallbackUser = pvCallbackUser; 2508 2509 // these added with V0.9.20 (2002-07-06) [umoeller] 2510 pDom->paSystemIds = paSystemIds; 2511 pDom->cSystemIds = cSystemIds; 2512 2513 lstInit(&pDom->llElementStack, 2514 TRUE); // auto-free 2515 2516 // create the document node 2517 if (!(arc = xmlCreateDomNode(NULL, // no parent 2518 DOMNODE_DOCUMENT, 2519 NULL, 2520 0, 2521 &pDocument))) 2522 { 2523 // store the document in the DOM 2524 pDom->pDocumentNode = (PDOMDOCUMENTNODE)pDocument; 2525 2526 // push the document on the stack so the handlers 2527 // will append to that 2528 PushElementStack(pDom, 2529 pDocument); 2530 2531 pDom->pParser = XML_ParserCreate(NULL); 2532 2533 if (!pDom->pParser) 2534 arc = ERROR_NOT_ENOUGH_MEMORY; 2535 else 2476 2536 { 2477 // store the document in the DOM 2478 pDom->pDocumentNode = (PDOMDOCUMENTNODE)pDocument; 2479 2480 // push the document on the stack so the handlers 2481 // will append to that 2482 PushElementStack(pDom, 2483 pDocument); 2484 2485 pDom->pParser = XML_ParserCreate(NULL); 2486 2487 if (!pDom->pParser) 2488 arc = ERROR_NOT_ENOUGH_MEMORY; 2489 else 2537 if (pfnGetCPData) 2538 XML_SetUnknownEncodingHandler(pDom->pParser, 2539 UnknownEncodingHandler, 2540 pDom); // user data 2541 2542 XML_SetParamEntityParsing(pDom->pParser, 2543 XML_PARAM_ENTITY_PARSING_ALWAYS); 2544 2545 XML_SetElementHandler(pDom->pParser, 2546 StartElementHandler, 2547 EndElementHandler); 2548 2549 XML_SetCharacterDataHandler(pDom->pParser, 2550 CharacterDataHandler); 2551 2552 // XML_SetProcessingInstructionHandler(XML_Parser parser, 2553 // XML_ProcessingInstructionHandler handler); 2554 2555 2556 if (flParserFlags & DF_PARSECOMMENTS) 2557 XML_SetCommentHandler(pDom->pParser, 2558 CommentHandler); 2559 2560 if ( (pfnExternalHandler) 2561 || (cSystemIds) // V0.9.20 (2002-07-06) [umoeller] 2562 ) 2563 XML_SetExternalEntityRefHandler(pDom->pParser, 2564 ExternalEntityRefHandler); 2565 2566 if (flParserFlags & DF_PARSEDTD) 2490 2567 { 2491 if (pfnGetCPData) 2492 XML_SetUnknownEncodingHandler(pDom->pParser, 2493 UnknownEncodingHandler, 2494 pDom); // user data 2568 XML_SetDoctypeDeclHandler(pDom->pParser, 2569 StartDoctypeDeclHandler, 2570 EndDoctypeDeclHandler); 2571 2572 XML_SetNotationDeclHandler(pDom->pParser, 2573 NotationDeclHandler); 2574 2575 XML_SetElementDeclHandler(pDom->pParser, 2576 ElementDeclHandler); 2577 2578 XML_SetAttlistDeclHandler(pDom->pParser, 2579 AttlistDeclHandler); 2580 2581 XML_SetEntityDeclHandler(pDom->pParser, 2582 EntityDeclHandler); 2495 2583 2496 2584 XML_SetParamEntityParsing(pDom->pParser, 2497 2585 XML_PARAM_ENTITY_PARSING_ALWAYS); 2498 2499 XML_SetElementHandler(pDom->pParser,2500 StartElementHandler,2501 EndElementHandler);2502 2503 XML_SetCharacterDataHandler(pDom->pParser,2504 CharacterDataHandler);2505 2506 // XML_SetProcessingInstructionHandler(XML_Parser parser,2507 // XML_ProcessingInstructionHandler handler);2508 2509 2510 if (flParserFlags & DF_PARSECOMMENTS)2511 XML_SetCommentHandler(pDom->pParser,2512 CommentHandler);2513 2514 if ( (pfnExternalHandler)2515 || (cSystemIds) // V0.9.20 (2002-07-06) [umoeller]2516 )2517 XML_SetExternalEntityRefHandler(pDom->pParser,2518 ExternalEntityRefHandler);2519 2520 if (flParserFlags & DF_PARSEDTD)2521 {2522 XML_SetDoctypeDeclHandler(pDom->pParser,2523 StartDoctypeDeclHandler,2524 EndDoctypeDeclHandler);2525 2526 XML_SetNotationDeclHandler(pDom->pParser,2527 NotationDeclHandler);2528 2529 XML_SetElementDeclHandler(pDom->pParser,2530 ElementDeclHandler);2531 2532 XML_SetAttlistDeclHandler(pDom->pParser,2533 AttlistDeclHandler);2534 2535 XML_SetEntityDeclHandler(pDom->pParser,2536 EntityDeclHandler);2537 2538 XML_SetParamEntityParsing(pDom->pParser,2539 XML_PARAM_ENTITY_PARSING_ALWAYS);2540 }2541 2542 // XML_SetXmlDeclHandler ... do we care for this? I guess not2543 2544 // pass the XMLDOM as user data to the handlers2545 XML_SetUserData(pDom->pParser,2546 pDom);2547 2586 } 2587 2588 // XML_SetXmlDeclHandler ... do we care for this? I guess not 2589 2590 // pass the XMLDOM as user data to the handlers 2591 XML_SetUserData(pDom->pParser, 2592 pDom); 2548 2593 } 2549 2594 }
Note:
See TracChangeset
for help on using the changeset viewer.