📄 node.c
字号:
/////////////////////////////////////////////////////////////////////////////// Copyright (c) 2000-2003 Intel Corporation // All rights reserved. //// Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: //// * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // * Neither name of Intel Corporation nor the names of its contributors // may be used to endorse or promote products derived from this software // without specific prior written permission.// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE./////////////////////////////////////////////////////////////////////////////#include "ixmlparser.h"/*================================================================* ixmlNode_init* Intializes a node.* External function.**=================================================================*/voidixmlNode_init( IN IXML_Node * nodeptr ){ assert( nodeptr != NULL ); memset( nodeptr, 0, sizeof( IXML_Node ) );}/*================================================================* ixmlCDATASection_init* Initializes a CDATASection node.* External function.**=================================================================*/voidixmlCDATASection_init( IN IXML_CDATASection * nodeptr ){ memset( nodeptr, 0, sizeof( IXML_CDATASection ) );}/*================================================================* ixmlCDATASection_free* frees a CDATASection node.* External function.**=================================================================*/voidixmlCDATASection_free( IN IXML_CDATASection * nodeptr ){ if( nodeptr != NULL ) { ixmlNode_free( ( IXML_Node * ) nodeptr ); }}/*================================================================* ixmlNode_freeSingleNode* frees a node content.* Internal to parser only.**=================================================================*/voidixmlNode_freeSingleNode( IN IXML_Node * nodeptr ){ IXML_Element *element = NULL; if( nodeptr != NULL ) { if( nodeptr->nodeName != NULL ) { free( nodeptr->nodeName ); } if( nodeptr->nodeValue != NULL ) { free( nodeptr->nodeValue ); } if( nodeptr->namespaceURI != NULL ) { free( nodeptr->namespaceURI ); } if( nodeptr->prefix != NULL ) { free( nodeptr->prefix ); } if( nodeptr->localName != NULL ) { free( nodeptr->localName ); } if( nodeptr->nodeType == eELEMENT_NODE ) { element = ( IXML_Element * ) nodeptr; free( element->tagName ); } free( nodeptr ); }}/*================================================================* ixmlNode_free* Frees all nodes under nodeptr subtree.* External function.**=================================================================*/voidixmlNode_free( IN IXML_Node * nodeptr ){ if( nodeptr != NULL ) { ixmlNode_free( nodeptr->firstChild ); ixmlNode_free( nodeptr->nextSibling ); ixmlNode_free( nodeptr->firstAttr ); ixmlNode_freeSingleNode( nodeptr ); }}/*================================================================* ixmlNode_getNodeName* Returns the nodename(the qualified name)* External function.**=================================================================*/const DOMStringixmlNode_getNodeName( IN IXML_Node * nodeptr ){ if( nodeptr != NULL ) { return ( nodeptr->nodeName ); } return NULL;}/*================================================================* ixmlNode_getLocalName* Returns the node local name* External function. **=================================================================*/const DOMStringixmlNode_getLocalName( IN IXML_Node * nodeptr ){ if( nodeptr != NULL ) { return ( nodeptr->localName ); } return NULL;}/*================================================================* ixmlNode_setNamespaceURI* sets the namespace URI of the node.* Internal function.* Return:* IXML_SUCCESS or failure **=================================================================*/intixmlNode_setNamespaceURI( IN IXML_Node * nodeptr, IN char *namespaceURI ){ if( nodeptr == NULL ) { return IXML_INVALID_PARAMETER; } if( nodeptr->namespaceURI != NULL ) { free( nodeptr->namespaceURI ); nodeptr->namespaceURI = NULL; } if( namespaceURI != NULL ) { nodeptr->namespaceURI = strdup( namespaceURI ); if( nodeptr->namespaceURI == NULL ) { return IXML_INSUFFICIENT_MEMORY; } } return IXML_SUCCESS;}/*================================================================* ixmlNode_setPrefix* set the prefix of the node.* Internal to parser only.* Returns: * IXML_SUCCESS or failure.**=================================================================*/intixmlNode_setPrefix( IN IXML_Node * nodeptr, IN char *prefix ){ if( nodeptr == NULL ) { return IXML_INVALID_PARAMETER; } if( nodeptr->prefix != NULL ) { free( nodeptr->prefix ); nodeptr->prefix = NULL; } if( prefix != NULL ) { nodeptr->prefix = strdup( prefix ); if( nodeptr->prefix == NULL ) { return IXML_INSUFFICIENT_MEMORY; } } return IXML_SUCCESS;}/*================================================================* ixmlNode_setLocalName* set the localName of the node.* Internal to parser only.* Returns: * IXML_SUCCESS or failure.**=================================================================*/intixmlNode_setLocalName( IN IXML_Node * nodeptr, IN char *localName ){ assert( nodeptr != NULL ); if( nodeptr->localName != NULL ) { free( nodeptr->localName ); nodeptr->localName = NULL; } if( localName != NULL ) { nodeptr->localName = strdup( localName ); if( nodeptr->localName == NULL ) { return IXML_INSUFFICIENT_MEMORY; } } return IXML_SUCCESS;}/*================================================================* ixmlNode_getNodeNamespaceURI* Returns the node namespaceURI* External function.* Returns: * the namespaceURI of the node**=================================================================*/const DOMStringixmlNode_getNamespaceURI( IN IXML_Node * nodeptr ){ DOMString retNamespaceURI = NULL; if( nodeptr != NULL ) { retNamespaceURI = nodeptr->namespaceURI; } return retNamespaceURI;}/*================================================================* ixmlNode_getPrefix* Returns the node prefix* External function.* Returns: * the prefix of the node.**=================================================================*/DOMStringixmlNode_getPrefix( IN IXML_Node * nodeptr ){ DOMString prefix = NULL; if( nodeptr != NULL ) { prefix = nodeptr->prefix; } return prefix;}/*================================================================* ixmlNode_getNodeValue* Returns the nodeValue of this node* External function.* Return:* the nodeValue of the node.**=================================================================*/DOMStringixmlNode_getNodeValue( IN IXML_Node * nodeptr ){ if( nodeptr != NULL ) { return ( nodeptr->nodeValue ); } return NULL;}/*================================================================* ixmlNode_setNodeValue* Sets the nodeValue* Internal function.* Returns: * IXML_SUCCESS or failure**=================================================================*/intixmlNode_setNodeValue( IN IXML_Node * nodeptr, IN char *newNodeValue ){ int rc = IXML_SUCCESS; if( nodeptr == NULL ) { return IXML_INVALID_PARAMETER; } if( nodeptr->nodeValue != NULL ) { free( nodeptr->nodeValue ); nodeptr->nodeValue = NULL; } if( newNodeValue != NULL ) { nodeptr->nodeValue = strdup( newNodeValue ); if( nodeptr->nodeValue == NULL ) { return IXML_INSUFFICIENT_MEMORY; } } return rc;}/*================================================================* ixmlNode_getNodeType* Gets the NodeType of this node* External function.**=================================================================*/const unsigned shortixmlNode_getNodeType( IN IXML_Node * nodeptr ){ if( nodeptr != NULL ) { return ( nodeptr->nodeType ); } else { return ( eINVALID_NODE ); }}/*================================================================* ixmlNode_getParentNode* Get the parent node* External function.* Return: * *=================================================================*/IXML_Node *ixmlNode_getParentNode( IN IXML_Node * nodeptr ){ if( nodeptr != NULL ) { return nodeptr->parentNode; } else { return NULL; }}/*================================================================* ixmlNode_getFirstChild* Returns the first child of nodeptr.* External function.**=================================================================*/IXML_Node *ixmlNode_getFirstChild( IN IXML_Node * nodeptr ){ if( nodeptr != NULL ) { return nodeptr->firstChild; } else { return NULL; }}/*================================================================* ixmlNode_getLastChild* Returns the last child of nodeptr.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -