⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 document.c

📁 电驴下载工具eMule0.47aVeryCD的源代码,可作分析测试也可用于P2P软件的开发研究.
💻 C
📖 第 1 页 / 共 2 页
字号:
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }

    attrNode->n.ownerDocument = doc;

  ErrorHandler:
    *rtAttr = attrNode;
    return errCode;

}

/*================================================================
*   ixmlDocument_createAttribute
*       Creates an attribute of the given name.             
*       External function.
*   Parameters:
*       name: The name of the Attribute node.
*   Return Value:   
*       A new attr object with the nodeName attribute set to the
*       given name, and the localName, prefix and namespaceURI set to NULL.
*       The value of the attribute is the empty string.
*
================================================================*/
IXML_Attr *
ixmlDocument_createAttribute( IN IXML_Document * doc,
                              IN char *name )
{
    IXML_Attr *attrNode = NULL;

    ixmlDocument_createAttributeEx( doc, name, &attrNode );
    return attrNode;

}

/*================================================================
*   ixmlDocument_createAttributeNSEx
*       Creates an attrbute of the given name and namespace URI
*       External function.
*   Parameters:
*       namespaceURI: the namespace fo the attribute to create
*       qualifiedName: qualifiedName of the attribute to instantiate
*   Return Value:
*       IXML_SUCCESS
*       IXML_INVALID_PARAMETER:     if either doc,namespaceURI or qualifiedName is NULL
*       IXML_INSUFFICIENT_MEMORY:   if not enough memory to finish this operations.
*
*=================================================================*/
int
ixmlDocument_createAttributeNSEx( IN IXML_Document * doc,
                                  IN DOMString namespaceURI,
                                  IN DOMString qualifiedName,
                                  OUT IXML_Attr ** rtAttr )
{
    IXML_Attr *attrNode = NULL;
    int errCode = IXML_SUCCESS;

    if( ( doc == NULL ) || ( namespaceURI == NULL )
        || ( qualifiedName == NULL ) ) {
        errCode = IXML_INVALID_PARAMETER;
        goto ErrorHandler;
    }

    errCode =
        ixmlDocument_createAttributeEx( doc, qualifiedName, &attrNode );
    if( errCode != IXML_SUCCESS ) {
        goto ErrorHandler;
    }
    // set the namespaceURI field 
    attrNode->n.namespaceURI = strdup( namespaceURI );
    if( attrNode->n.namespaceURI == NULL ) {
        ixmlAttr_free( attrNode );
        attrNode = NULL;
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }
    // set the localName and prefix 
    errCode =
        ixmlNode_setNodeName( ( IXML_Node * ) attrNode, qualifiedName );
    if( errCode != IXML_SUCCESS ) {
        ixmlAttr_free( attrNode );
        attrNode = NULL;
        goto ErrorHandler;
    }

  ErrorHandler:
    *rtAttr = attrNode;
    return errCode;

}

/*================================================================
*   ixmlDocument_createAttributeNS
*       Creates an attrbute of the given name and namespace URI
*       External function.
*   Parameters:
*       namespaceURI: the namespace fo the attribute to create
*       qualifiedName: qualifiedName of the attribute to instantiate
*   Return Value:   
*       Creates an attribute node with the given namespaceURI and
*       qualifiedName. The prefix and localname are extracted from 
*       the qualifiedName. The node value is empty.
*	
*=================================================================*/
IXML_Attr *
ixmlDocument_createAttributeNS( IN IXML_Document * doc,
                                IN DOMString namespaceURI,
                                IN DOMString qualifiedName )
{
    IXML_Attr *attrNode = NULL;

    ixmlDocument_createAttributeNSEx( doc, namespaceURI, qualifiedName,
                                      &attrNode );
    return attrNode;
}

/*================================================================
*   ixmlDocument_createCDATASectionEx
*       Creates an CDATASection node whose value is the specified string
*       External function.
*   Parameters:
*       data: the data for the CDATASection contents.
*   Return Value:
*       IXML_SUCCESS
*       IXML_INVALID_PARAMETER:     if either doc or data is NULL
*       IXML_INSUFFICIENT_MEMORY:   if not enough memory to finish this operations.
*
*=================================================================*/
int
ixmlDocument_createCDATASectionEx( IN IXML_Document * doc,
                                   IN DOMString data,
                                   OUT IXML_CDATASection ** rtCD )
{
    int errCode = IXML_SUCCESS;
    IXML_CDATASection *cDSectionNode = NULL;

    if( ( doc == NULL ) || ( data == NULL ) ) {
        errCode = IXML_INVALID_PARAMETER;
        goto ErrorHandler;
    }

    cDSectionNode =
        ( IXML_CDATASection * ) malloc( sizeof( IXML_CDATASection ) );
    if( cDSectionNode == NULL ) {
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }

    ixmlCDATASection_init( cDSectionNode );

    cDSectionNode->n.nodeType = eCDATA_SECTION_NODE;
    cDSectionNode->n.nodeName = strdup( CDATANODENAME );
    if( cDSectionNode->n.nodeName == NULL ) {
        ixmlCDATASection_free( cDSectionNode );
        cDSectionNode = NULL;
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }

    cDSectionNode->n.nodeValue = strdup( data );
    if( cDSectionNode->n.nodeValue == NULL ) {
        ixmlCDATASection_free( cDSectionNode );
        cDSectionNode = NULL;
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }

    cDSectionNode->n.ownerDocument = doc;

  ErrorHandler:
    *rtCD = cDSectionNode;
    return errCode;

}

/*================================================================
*   ixmlDocument_createCDATASection
*       Creates an CDATASection node whose value is the specified string
*       External function.
*   Parameters:
*       data: the data for the CDATASection contents.
*   Return Value:   
*       The new CDATASection object.
*	
*=================================================================*/
IXML_CDATASection *
ixmlDocument_createCDATASection( IN IXML_Document * doc,
                                 IN DOMString data )
{

    IXML_CDATASection *cDSectionNode = NULL;

    ixmlDocument_createCDATASectionEx( doc, data, &cDSectionNode );
    return cDSectionNode;
}

/*================================================================
*   ixmlDocument_createElementNSEx
*       Creates an element of the given qualified name and namespace URI.
*       External function.
*   Parameters:
*       namespaceURI: the namespace URI of the element to create.
*       qualifiedName: the qualified name of the element to instantiate.
*   Return Value:   
*   Return Value:
*       IXML_SUCCESS
*       IXML_INVALID_PARAMETER:     if either doc,namespaceURI or qualifiedName is NULL
*       IXML_INSUFFICIENT_MEMORY:   if not enough memory to finish this operations.
*
*=================================================================*/
int
ixmlDocument_createElementNSEx( IN IXML_Document * doc,
                                IN DOMString namespaceURI,
                                IN DOMString qualifiedName,
                                OUT IXML_Element ** rtElement )
{

    IXML_Element *newElement = NULL;
    int errCode = IXML_SUCCESS;

    if( ( doc == NULL ) || ( namespaceURI == NULL )
        || ( qualifiedName == NULL ) ) {
        errCode = IXML_INVALID_PARAMETER;
        goto ErrorHandler;
    }

    errCode =
        ixmlDocument_createElementEx( doc, qualifiedName, &newElement );
    if( errCode != IXML_SUCCESS ) {
        goto ErrorHandler;
    }
    // set the namespaceURI field 
    newElement->n.namespaceURI = strdup( namespaceURI );
    if( newElement->n.namespaceURI == NULL ) {
        ixmlElement_free( newElement );
        newElement = NULL;
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }
    // set the localName and prefix 
    errCode =
        ixmlNode_setNodeName( ( IXML_Node * ) newElement, qualifiedName );
    if( errCode != IXML_SUCCESS ) {
        ixmlElement_free( newElement );
        newElement = NULL;
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }

    newElement->n.nodeValue = NULL;

  ErrorHandler:
    *rtElement = newElement;
    return errCode;

}

/*================================================================
*   ixmlDocument_createElementNS
*       Creates an element of the given qualified name and namespace URI.
*       External function.
*   Parameters:
*       namespaceURI: the namespace URI of the element to create.
*       qualifiedName: the qualified name of the element to instantiate.
*   Return Value:   
*       The new element object with tagName qualifiedName, prefix and
*       localName extraced from qualfiedName, nodeName of qualfiedName,
*	    namespaceURI of namespaceURI.
*
*=================================================================*/
IXML_Element *
ixmlDocument_createElementNS( IN IXML_Document * doc,
                              IN DOMString namespaceURI,
                              IN DOMString qualifiedName )
{
    IXML_Element *newElement = NULL;

    ixmlDocument_createElementNSEx( doc, namespaceURI, qualifiedName,
                                    &newElement );
    return newElement;
}

/*================================================================
*   ixmlDocument_getElementsByTagName
*       Returns a nodeList of all the Elements with a given tag name
*       in the order in which they are encountered in a preorder traversal
*       of the document tree.
*       External function.
*   Parameters:
*       tagName: the name of the tag to match on. The special value "*"
*                matches all tags.
*   Return Value:
*       A new nodeList object containing all the matched Elements.    
*
*=================================================================*/
IXML_NodeList *
ixmlDocument_getElementsByTagName( IN IXML_Document * doc,
                                   IN char *tagName )
{
    IXML_NodeList *returnNodeList = NULL;

    if( ( doc == NULL ) || ( tagName == NULL ) ) {
        return NULL;
    }

    ixmlNode_getElementsByTagName( ( IXML_Node * ) doc, tagName,
                                   &returnNodeList );
    return returnNodeList;
}

/*================================================================
*   ixmlDocument_getElementsByTagNameNS
*       Returns a nodeList of all the Elements with a given local name and
*       namespace URI in the order in which they are encountered in a 
*       preorder traversal of the document tree.
*       External function.
*   Parameters:
*       namespaceURI: the namespace of the elements to match on. The special
*               value "*" matches all namespaces.
*       localName: the local name of the elements to match on. The special
*               value "*" matches all local names.
*   Return Value:
*       A new nodeList object containing all the matched Elements.    
*
*=================================================================*/
IXML_NodeList *
ixmlDocument_getElementsByTagNameNS( IN IXML_Document * doc,
                                     IN DOMString namespaceURI,
                                     IN DOMString localName )
{
    IXML_NodeList *returnNodeList = NULL;

    if( ( doc == NULL ) || ( namespaceURI == NULL )
        || ( localName == NULL ) ) {
        return NULL;
    }

    ixmlNode_getElementsByTagNameNS( ( IXML_Node * ) doc, namespaceURI,
                                     localName, &returnNodeList );
    return returnNodeList;
}

/*================================================================
*   ixmlDocument_getElementById
*       Returns the element whose ID is given by tagName. If no such
*       element exists, returns null. 
*       External function.
*   Parameter:
*       tagName: the tag name for an element.
*   Return Values:
*       The matching element.
*
*=================================================================*/
IXML_Element *
ixmlDocument_getElementById( IN IXML_Document * doc,
                             IN DOMString tagName )
{
    IXML_Element *rtElement = NULL;
    IXML_Node *nodeptr = ( IXML_Node * ) doc;
    const char *name;

    if( ( nodeptr == NULL ) || ( tagName == NULL ) ) {
        return rtElement;
    }

    if( ixmlNode_getNodeType( nodeptr ) == eELEMENT_NODE ) {
        name = ixmlNode_getNodeName( nodeptr );
        if( name == NULL ) {
            return rtElement;
        }

        if( strcmp( tagName, name ) == 0 ) {
            rtElement = ( IXML_Element * ) nodeptr;
            return rtElement;
        } else {
            rtElement = ixmlDocument_getElementById( ( IXML_Document * )
                                                     ixmlNode_getFirstChild
                                                     ( nodeptr ),
                                                     tagName );
            if( rtElement == NULL ) {
                rtElement = ixmlDocument_getElementById( ( IXML_Document
                                                           * )
                                                         ixmlNode_getNextSibling
                                                         ( nodeptr ),
                                                         tagName );
            }
        }
    } else {
        rtElement = ixmlDocument_getElementById( ( IXML_Document * )
                                                 ixmlNode_getFirstChild
                                                 ( nodeptr ), tagName );
        if( rtElement == NULL ) {
            rtElement = ixmlDocument_getElementById( ( IXML_Document * )
                                                     ixmlNode_getNextSibling
                                                     ( nodeptr ),
                                                     tagName );
        }
    }

    return rtElement;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -