Beispiel #1
0
/*================================================================
*   ixmlNode_cloneElement
*       returns a clone of element node
*       Internal to parser only.
*
*=================================================================*/
IXML_Element *
ixmlNode_cloneElement( IN IXML_Element * nodeptr )
{
    IXML_Element *newElement;
    IXML_Node *elementNode;
    IXML_Node *srcNode;
    int rc;

    assert( nodeptr != NULL );

    newElement = ( IXML_Element * ) malloc( sizeof( IXML_Element ) );
    if( newElement == NULL ) {
        return NULL;
    }

    ixmlElement_init( newElement );
    rc = ixmlElement_setTagName( newElement, nodeptr->tagName );
    if( rc != IXML_SUCCESS ) {
        ixmlElement_free( newElement );
        return NULL;
    }

    elementNode = ( IXML_Node * ) newElement;
    srcNode = ( IXML_Node * ) nodeptr;
    rc = ixmlNode_setNodeName( elementNode, srcNode->nodeName );
    if( rc != IXML_SUCCESS ) {
        ixmlElement_free( newElement );
        return NULL;
    }

    rc = ixmlNode_setNodeValue( elementNode, srcNode->nodeValue );
    if( rc != IXML_SUCCESS ) {
        ixmlElement_free( newElement );
        return NULL;
    }

    rc = ixmlNode_setNamespaceURI( elementNode, srcNode->namespaceURI );
    if( rc != IXML_SUCCESS ) {
        ixmlElement_free( newElement );
        return NULL;
    }

    rc = ixmlNode_setPrefix( elementNode, srcNode->prefix );
    if( rc != IXML_SUCCESS ) {
        ixmlElement_free( newElement );
        return NULL;
    }

    rc = ixmlNode_setLocalName( elementNode, srcNode->localName );
    if( rc != IXML_SUCCESS ) {
        ixmlElement_free( newElement );
        return NULL;
    }

    elementNode->nodeType = eELEMENT_NODE;

    return newElement;

}
Beispiel #2
0
/*!
 * \brief Returns a clone of an attribute node.
 *
 * \return A clone of an attribute node.
 */
static IXML_Attr *ixmlNode_cloneAttr(
    /*! [in] The \b Node to clone. */
    IXML_Attr *nodeptr)
{
    IXML_Attr *newAttr;
    IXML_Node *attrNode;
    IXML_Node *srcNode;
    int rc;

    assert(nodeptr != NULL);

    newAttr = (IXML_Attr *)malloc(sizeof (IXML_Attr));
    if (newAttr == NULL) {
        return NULL;
    }

    ixmlAttr_init(newAttr);
    attrNode = (IXML_Node *)newAttr;
    srcNode = (IXML_Node *)nodeptr;

    rc = ixmlNode_setNodeName(attrNode, srcNode->nodeName);
    if (rc != IXML_SUCCESS) {
        ixmlAttr_free(newAttr);
        return NULL;
    }

    rc = ixmlNode_setNodeValue(attrNode, srcNode->nodeValue);
    if (rc != IXML_SUCCESS) {
        ixmlAttr_free(newAttr);
        return NULL;
    }

    /* Check to see whether we need to split prefix and localname for attribute */
    rc = ixmlNode_setNamespaceURI(attrNode, srcNode->namespaceURI);
    if (rc != IXML_SUCCESS) {
        ixmlAttr_free(newAttr);
        return NULL;
    }

    rc = ixmlNode_setPrefix(attrNode, srcNode->prefix);
    if (rc != IXML_SUCCESS) {
        ixmlAttr_free(newAttr);
        return NULL;
    }

    rc = ixmlNode_setLocalName(attrNode, srcNode->localName);
    if (rc != IXML_SUCCESS) {
        ixmlAttr_free(newAttr);
        return NULL;
    }

    attrNode->nodeType = eATTRIBUTE_NODE;

    return newAttr;
}
/*================================================================
*   ixmlNode_setNodeProperties
*       Internal to parser only.
*
*=================================================================*/
int
ixmlNode_setNodeProperties( IN IXML_Node * destNode,
                            IN IXML_Node * src )
{

    int rc;

    assert( destNode != NULL || src != NULL );

    rc = ixmlNode_setNodeValue( destNode, src->nodeValue );
    if( rc != IXML_SUCCESS ) {
        goto ErrorHandler;
    }

    rc = ixmlNode_setLocalName( destNode, src->localName );
    if( rc != IXML_SUCCESS ) {
        goto ErrorHandler;
    }

    rc = ixmlNode_setPrefix( destNode, src->prefix );
    if( rc != IXML_SUCCESS ) {
        goto ErrorHandler;
    }
    // set nodetype
    destNode->nodeType = src->nodeType;

    return IXML_SUCCESS;

  ErrorHandler:
    if( destNode->nodeName != NULL ) {
        ixml_free( destNode->nodeName );
        destNode->nodeName = NULL;
    }
    if( destNode->nodeValue != NULL ) {
        ixml_free( destNode->nodeValue );
        destNode->nodeValue = NULL;
    }
    if( destNode->localName != NULL ) {
        ixml_free( destNode->localName );
        destNode->localName = NULL;
    }

    return IXML_INSUFFICIENT_MEMORY;
}