| 2445 | |
| 2446 | |
| 2447 | XMLError XMLDocument::Parse( const char* xml, size_t nBytes ) |
| 2448 | { |
| 2449 | Clear(); |
| 2450 | |
| 2451 | if ( nBytes == 0 || !xml || !*xml ) { |
| 2452 | SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); |
| 2453 | return _errorID; |
| 2454 | } |
| 2455 | if ( nBytes == static_cast<size_t>(-1) ) { |
| 2456 | nBytes = strlen( xml ); |
| 2457 | } |
| 2458 | TIXMLASSERT( _charBuffer == 0 ); |
| 2459 | _charBuffer = new char[ nBytes+1 ]; |
| 2460 | memcpy( _charBuffer, xml, nBytes ); |
| 2461 | _charBuffer[nBytes] = 0; |
| 2462 | |
| 2463 | Parse(); |
| 2464 | if ( Error() ) { |
| 2465 | // clean up now essentially dangling memory. |
| 2466 | // and the parse fail can put objects in the |
| 2467 | // pools that are dead and inaccessible. |
| 2468 | DeleteChildren(); |
| 2469 | _elementPool.Clear(); |
| 2470 | _attributePool.Clear(); |
| 2471 | _textPool.Clear(); |
| 2472 | _commentPool.Clear(); |
| 2473 | } |
| 2474 | return _errorID; |
| 2475 | } |
| 2476 | |
| 2477 | |
| 2478 | void XMLDocument::Print( XMLPrinter* streamer ) const |
no test coverage detected