/*================================================================
*   ixmlNode_getChildNodes
*       Returns a IXML_NodeList of all the child nodes of nodeptr.
*       External function.
*   
*=================================================================*/
IXML_NodeList *
ixmlNode_getChildNodes( IN IXML_Node * nodeptr )
{
    IXML_Node *tempNode;
    IXML_NodeList *newNodeList;
    int rc;

    if( nodeptr == NULL ) {
        return NULL;
    }

    newNodeList = ( IXML_NodeList * ) ixml_malloc( sizeof( IXML_NodeList ) );
    if( newNodeList == NULL ) {
        return NULL;
    }

    ixmlNodeList_init( newNodeList );

    tempNode = nodeptr->firstChild;
    while( tempNode != NULL ) {
        rc = ixmlNodeList_addToNodeList( &newNodeList, tempNode );
        if( rc != IXML_SUCCESS ) {
            ixmlNodeList_free( newNodeList );
            return NULL;
        }

        tempNode = tempNode->nextSibling;
    }
    return newNodeList;
}
Exemplo n.º 2
0
/*================================================================
*   ixmlNodeList_addToNodeList
*       Add a node to nodelist
*       Internal to parser only.
*
*=================================================================*/
int
ixmlNodeList_addToNodeList( IN IXML_NodeList ** nList,
                            IN IXML_Node * add )
{
    IXML_NodeList *traverse,
     *p = NULL;
    IXML_NodeList *newListItem;

    ixml_assert( add != NULL );

    if( add == NULL ) {
        return IXML_FAILED;
    }

    if( *nList == NULL )        // nodelist is empty
    {
        *nList = ( IXML_NodeList * ) IXML_MALLOC( sizeof( IXML_NodeList ) );
        if( *nList == NULL ) {
            return IXML_INSUFFICIENT_MEMORY;
        }

        ixmlNodeList_init( *nList );
    }

    if( ( *nList )->nodeItem == NULL ) {
        ( *nList )->nodeItem = add;
    } else {
        traverse = *nList;
        while( traverse != NULL ) {
            p = traverse;
            traverse = traverse->next;
        }

        newListItem =
            ( IXML_NodeList * ) IXML_MALLOC( sizeof( IXML_NodeList ) );
        if( newListItem == NULL ) {
            return IXML_INSUFFICIENT_MEMORY;
        }
        p->next = newListItem;
        newListItem->nodeItem = add;
        newListItem->next = NULL;
    }

    return IXML_SUCCESS;
}