コード例 #1
0
ファイル: xmlelement.cpp プロジェクト: alilloyd/livecode
// MDW-2013-07-09: [[ RevXmlXPath ]]
int CXMLElement::AttributeCount(char *attributename)
{
	if (!isinited()) return 0;
	CXMLAttribute tattribute;
	int attributecount = 0;
	if (GetFirstAttribute(&tattribute)){
		do {
			if (!attributename || 
				util_strnicmp(tattribute.GetName(),attributename,strlen(attributename)) == 0)
				attributecount++;
		} while (tattribute.GoNext());
	}
	return attributecount;
}
コード例 #2
0
ファイル: xmlelement.cpp プロジェクト: alilloyd/livecode
/*GetAttribute - returns value of specified attribute
attname - name of attribute to look for
isbuffered - if true returns copy of attribute value (must be freed by caller).
returns NULL if specified attribute not found
*/
char *CXMLElement::GetAttributeValue(char *attname, Bool isbuffered)
{
	if (!isinited()) 
		return NULL;

	// OK-2009-01-05: [[Bug 7586]] - Some elements may have a "namespace". This is not regarded by libXML
	// as one of the elements' attributes, but is stored separately. If the required attribute is called 
	// "xmlns", then we retreive the namespace instead of using GetAttributeValue.
	if (strcasecmp(attname, "xmlns") == 0)
	{
		xmlNs *t_namespace;
		t_namespace = NULL;
		GetNamespace(t_namespace);

		if (t_namespace != NULL && t_namespace -> href != NULL)
		{
			return strdup((char *)t_namespace -> href);
		}
	}

	if (isbuffered)
	{
		CXMLAttribute tattribute;
		if (GetFirstAttribute(&tattribute))
		{
			int attributecount = 1;
			do 
			{
				if (!attname || util_strnicmp(tattribute.GetName(), attname, strlen(attname)) == 0)
					return tattribute.GetContent();
			} while (tattribute.GoNext());
		}
	}
	else
		return (char *)xmlGetProp(element, (xmlChar *)attname);
	return NULL;
}