Example #1
0
static HRESULT WINAPI domcomment_appendData(
    IXMLDOMComment *iface,
    BSTR p)
{
    domcomment *This = impl_from_IXMLDOMComment( iface );
    xmlnode *pDOMNode = impl_from_IXMLDOMNode( This->node );
    xmlChar *pContent;
    HRESULT hr = S_FALSE;

    TRACE("%p\n", iface);

    /* Nothing to do if NULL or an Empty string passed in. */
    if(p == NULL || SysStringLen(p) == 0)
        return S_OK;

    pContent = xmlChar_from_wchar( (WCHAR*)p );
    if(pContent)
    {
        /* Older versions of libxml < 2.6.27 didn't correctly support
           xmlTextConcat on Comment nodes. Fallback to setting the
           contents directly if xmlTextConcat fails.

           NOTE: if xmlTextConcat fails, pContent is destroyed.
         */
        if(xmlTextConcat(pDOMNode->node, pContent, SysStringLen(p) ) == 0)
            hr = S_OK;
        else
        {
            xmlChar *pNew;
            pContent = xmlChar_from_wchar( (WCHAR*)p );
            if(pContent)
            {
                pNew = xmlStrcat(xmlNodeGetContent(pDOMNode->node), pContent);
                if(pNew)
                {
                    xmlNodeSetContent(pDOMNode->node, pNew);
                    hr = S_OK;
                }
                else
                    hr = E_FAIL;
            }
            else
                hr = E_FAIL;
        }
    }
    else
        hr = E_FAIL;

    return hr;
}
Example #2
0
bool gpl::xml::insertNodeByXPath(const char* nodeName, const char* nodeValue, int length /*= -1*/)
{
	if (m_xml->resource == NULL)
		return false;
	int len = strlen(nodeValue);
	if (length == 0 || len < length)
		return false;
	if (length == -1)
	{
		length = len;
	}
	//cout<<"resource->type:"<<m_xml->resource->type<<endl;
	switch (m_xml->resource->type)
	{
	case XPATH_NODESET://Object is a Node Set
		if (m_xml->resource->nodesetval == NULL)
			return false;
		xmlNodePtr cur, newNode;
		//取得第一个节点
		if ((cur = (*(m_xml->resource->nodesetval->nodeTab))) == NULL)
			return false;
		if (strlen(nodeName) == 0)
		{
			if (cur->children == NULL)
			{
				cur->children = xmlNewText((const xmlChar*)nodeValue);
				cur->last = cur->children;
				if (cur->last == NULL)
					return false;
			}
			else
				if (xmlTextConcat(cur->children, (const xmlChar *)nodeValue, length) < 0)
					return false;
		}
		else
		{
			if (strcmp(nodeName, XML_CDATA) == 0)
			{
				if ((newNode = xmlNewCDataBlock(m_xml->doc, (const xmlChar*)nodeValue, length)) == NULL)
					return false;
			}
			else
			{
				xmlNsPtr* ns = xmlGetNsList(m_xml->doc, cur);
				if ((newNode = xmlNewNode((ns == NULL ? NULL : (*ns)), (const xmlChar *)nodeName)) == NULL)
					return false;
				xmlNodeSetContent(newNode, (const xmlChar*)nodeValue);

			}
			//从最后的字节点位置进行追加
			if ((xmlAddChild(cur, newNode)) == NULL)
				return false;
		}
		break;
	case XPATH_XSLT_TREE://Object is an XSLT value tree
	case XPATH_BOOLEAN://Object is a Boolean
	case XPATH_NUMBER://Object is a number
	case XPATH_STRING://Object is a string
	case XPATH_POINT://Object is a point
	case XPATH_RANGE://是一个范围
	case XPATH_LOCATIONSET://Object is a Location Set
	case XPATH_USERS://Object is user defined
	case XPATH_UNDEFINED://Object is uninitialized
		return false;
		break;
	}
	return true;
}