Пример #1
0
/*================================================================
*   ixmlDocument_createDocumentEx
*       Creates an document object
*       Internal function.
*   Parameters:
*       rtDoc:  the document created or NULL on failure
*   Return Value:
*       IXML_SUCCESS
*       IXML_INSUFFICIENT_MEMORY:   if not enough memory to finish this operations.
*
*=================================================================*/
int
ixmlDocument_createDocumentEx( OUT IXML_Document ** rtDoc )
{
    IXML_Document *doc;
    int errCode = IXML_SUCCESS;

    doc = NULL;
    doc = ( IXML_Document * ) malloc( sizeof( IXML_Document ) );
    if( doc == NULL ) {
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }

    ixmlDocument_init( doc );

    doc->n.nodeName = strdup( DOCUMENTNODENAME );
    if( doc->n.nodeName == NULL ) {
        ixmlDocument_free( doc );
        doc = NULL;
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }

    doc->n.nodeType = eDOCUMENT_NODE;
    doc->n.ownerDocument = doc;

  ErrorHandler:
    *rtDoc = doc;
    return errCode;
}
/*================================================================
*   ixmlNode_cloneDoc
*       Returns a clone of document node
*       Internal to parser only.
*
*=================================================================*/
IXML_Document *
ixmlNode_cloneDoc( IN IXML_Document * nodeptr )
{
    IXML_Document *newDoc;
    IXML_Node *docNode;
    int rc;

    assert( nodeptr != NULL );
    newDoc = ( IXML_Document * ) ixml_malloc( sizeof( IXML_Document ) );
    if( newDoc == NULL ) {
        return NULL;
    }

    ixmlDocument_init( newDoc );
    docNode = ( IXML_Node * ) newDoc;

    rc = ixmlNode_setNodeName( docNode, DOCUMENTNODENAME );
    if( rc != IXML_SUCCESS ) {
        ixmlDocument_free( newDoc );
        return NULL;
    }

    newDoc->n.nodeType = eDOCUMENT_NODE;

    return newDoc;

}