📄 element.c
字号:
return IXML_FAILED;
}
}
Parser_freeNodeContent( &newAttrNode );
return IXML_SUCCESS;
}
/*================================================================
* ixmlElement_removeAttributeNS
* Removes an attribute by local name and namespace URI. The replacing
* attribute has the same namespace URI and local name, as well as
* the original prefix.
* External function.
*
* Parameters:
* namespaceURI: the namespace URI of the attribute to remove.
* localName: the local name of the atribute to remove.
*
* Return Value:
* IXML_SUCCESS or failure.
*
*=================================================================*/
int
ixmlElement_removeAttributeNS( IN IXML_Element * element,
IN DOMString namespaceURI,
IN DOMString localName )
{
IXML_Node *attrNode;
if( ( element == NULL ) || ( namespaceURI == NULL )
|| ( localName == NULL ) ) {
return IXML_INVALID_PARAMETER;
}
attrNode = element->n.firstAttr;
while( attrNode != NULL ) {
if( strcmp( attrNode->localName, localName ) == 0 &&
strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) {
break; //found it
} else {
attrNode = attrNode->nextSibling;
}
}
if( attrNode != NULL ) { // has the attribute
if( attrNode->nodeValue != NULL ) {
free( attrNode->nodeValue );
attrNode->nodeValue = NULL;
}
}
return IXML_SUCCESS;
}
/*================================================================
* ixmlElement_getAttributeNodeNS
* Retrieves an attr node by local name and namespace URI.
* External function.
*
* Parameter:
* namespaceURI: the namespace of the attribute to retrieve.
* localName: the local name of the attribute to retrieve.
*
* Return Value:
* The attr node with the specified attribute local name and
* namespace URI or null if there is no such attribute.
*
*=================================================================*/
IXML_Attr *
ixmlElement_getAttributeNodeNS( IN IXML_Element * element,
IN DOMString namespaceURI,
IN DOMString localName )
{
IXML_Node *attrNode;
if( ( element == NULL ) || ( namespaceURI == NULL )
|| ( localName == NULL ) ) {
return NULL;
}
attrNode = element->n.firstAttr;
while( attrNode != NULL ) {
if( strcmp( attrNode->localName, localName ) == 0 && strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) { // found it
break;
} else {
attrNode = attrNode->nextSibling;
}
}
return ( IXML_Attr * ) attrNode;
}
/*================================================================
* ixmlElement_setAttributeNodeNS
* Adds a new attribute. If an attribute with that local name and
* that namespace URI is already present in the element, it is replaced
* by the new one.
* External function.
*
* Parameter:
* newAttr: the attr node to add to the attribute list.
*
* Return Value:
* If the newAttr attribute replaces an existing attribute with the
* same local name and namespace, the replaced attr node is returned,
* otherwise null is returned.
*
*=================================================================*/
int
ixmlElement_setAttributeNodeNS( IN IXML_Element * element,
IN IXML_Attr * newAttr,
OUT IXML_Attr ** rtAttr )
{
IXML_Node *attrNode;
IXML_Node *node;
IXML_Node *prevAttr = NULL,
*nextAttr = NULL;
IXML_Node *preSib,
*nextSib;
if( ( element == NULL ) || ( newAttr == NULL ) ) {
return IXML_INVALID_PARAMETER;
}
if( newAttr->n.ownerDocument != element->n.ownerDocument ) {
return IXML_WRONG_DOCUMENT_ERR;
}
if( ( newAttr->ownerElement != NULL )
&& ( newAttr->ownerElement != element ) ) {
return IXML_INUSE_ATTRIBUTE_ERR;
}
newAttr->ownerElement = element;
node = ( IXML_Node * ) newAttr;
attrNode = element->n.firstAttr;
while( attrNode != NULL ) {
if( strcmp( attrNode->localName, node->localName ) == 0 &&
strcmp( attrNode->namespaceURI, node->namespaceURI ) == 0 ) {
break; //found it
} else {
attrNode = attrNode->nextSibling;
}
}
if( attrNode != NULL ) // already present, will replace by newAttr
{
preSib = attrNode->prevSibling;
nextSib = attrNode->nextSibling;
if( preSib != NULL ) {
preSib->nextSibling = node;
}
if( nextSib != NULL ) {
nextSib->prevSibling = node;
}
if( element->n.firstAttr == attrNode ) {
element->n.firstAttr = node;
}
*rtAttr = ( IXML_Attr * ) attrNode;
} else // add this attribute
{
if( element->n.firstAttr != NULL ) // element has attribute already
{
prevAttr = element->n.firstAttr;
nextAttr = prevAttr->nextSibling;
while( nextAttr != NULL ) {
prevAttr = nextAttr;
nextAttr = prevAttr->nextSibling;
}
prevAttr->nextSibling = node;
} else // this is the first attribute node
{
element->n.firstAttr = node;
node->prevSibling = NULL;
node->nextSibling = NULL;
}
if( rtAttr != NULL ) {
*rtAttr = NULL;
}
}
return IXML_SUCCESS;
}
/*================================================================
* ixmlElement_getElementsByTagNameNS
* Returns a nodeList of all the descendant Elements with a given
* local name and namespace in the order in which they are encountered
* in a preorder traversal of the element tree.
* External function.
*
* Parameters:
* namespaceURI: the namespace URI 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 *
ixmlElement_getElementsByTagNameNS( IN IXML_Element * element,
IN DOMString namespaceURI,
IN DOMString localName )
{
IXML_Node *node = ( IXML_Node * ) element;
IXML_NodeList *nodeList = NULL;
if( ( element != NULL ) && ( namespaceURI != NULL )
&& ( localName != NULL ) ) {
ixmlNode_getElementsByTagNameNS( node, namespaceURI, localName,
&nodeList );
}
return nodeList;
}
/*================================================================
* ixmlElement_hasAttribute
* Returns true when an attribute with a given name is specified on
* this element, false otherwise.
* External function.
*
* Parameters:
* name: the name of the attribute to look for.
*
* Return Value:
* ture if an attribute with the given name is specified on this
* element, false otherwise.
*
*=================================================================*/
BOOL
ixmlElement_hasAttribute( IN IXML_Element * element,
IN DOMString name )
{
IXML_Node *attrNode;
if( ( element == NULL ) || ( name == NULL ) ) {
return FALSE;
}
attrNode = element->n.firstAttr;
while( attrNode != NULL ) {
if( strcmp( attrNode->nodeName, name ) == 0 ) {
return TRUE;
} else {
attrNode = attrNode->nextSibling;
}
}
return FALSE;
}
/*================================================================
* ixmlElement_hasAttributeNS
* Returns true when attribute with a given local name and namespace
* URI is specified on this element, false otherwise.
* External function.
*
* Parameters:
* namespaceURI: the namespace URI of the attribute to look for.
* localName: the local name of the attribute to look for.
*
* Return Value:
* true if an attribute with the given local name and namespace URI
* is specified, false otherwise.
*
*=================================================================*/
BOOL
ixmlElement_hasAttributeNS( IN IXML_Element * element,
IN DOMString namespaceURI,
IN DOMString localName )
{
IXML_Node *attrNode;
if( ( element == NULL ) || ( namespaceURI == NULL )
|| ( localName == NULL ) ) {
return FALSE;
}
attrNode = element->n.firstAttr;
while( attrNode != NULL ) {
if( strcmp( attrNode->localName, localName ) == 0 &&
strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) {
return TRUE;
} else {
attrNode = attrNode->nextSibling;
}
}
return FALSE;
}
/*================================================================
* ixmlElement_free
* frees a element node.
* External function.
*
*=================================================================*/
void
ixmlElement_free( IN IXML_Element * element )
{
if( element != NULL ) {
ixmlNode_free( ( IXML_Node * ) element );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -