IMWMetadataElement* CMetadataElementsImpl::GetItem(VARIANT vIndex)
{
	IMWMetadataElement* pElement = NULL;

	switch(vIndex.vt)
	{
	case VT_BSTR:
		FindElementWithName(vIndex.bstrVal, pElement);
		break;

	case VT_I1:
	case VT_I2:		
	case VT_I4:		
	case VT_I8:
	case VT_INT:		
	case VT_UI1:
	case VT_UI2:
	case VT_UI4:
	case VT_UI8:
	case VT_UINT:	
		{
			_variant_t vtIndex(vIndex);	
			FindElementAt(static_cast<long>(vtIndex), pElement);
		}
		break;

	default:
		throw Workshare::Com::ComException(_T("Invalid index."), E_INVALIDARG);
	}	

	return pElement;
}
Example #2
0
/*
 * set node value for nodeName for existing node(or NULL for docroot) or create new. If value is NULL will be
 * created empty node
 * return pointer to the new element and NULL if not created
 */
void *setNode(xml_data *data, void *node, const char *nodeName,
		const char *value) {
	xmlNodePtr parent = node ? (xmlNodePtr) node : (xmlNodePtr) data->root;
	if (!nodeName)
		return (void *) NULL;
	xmlNodePtr fNode = (xmlNodePtr) FindElementWithName(data, parent, nodeName);
	xmlNodePtr addressNode = NULL;
	if (fNode) {
		xmlNodeSetContent(addressNode, (const xmlChar *) value);
	} else {
		addressNode = xmlNewChild(parent, NULL, (const xmlChar *) nodeName,
				(const xmlChar *) value);
	}
	return (void *) addressNode;
}
Example #3
0
/*
 * finds element with name nodeName in parsed data. NULL if nothing found. node - root elemnt for
 * node finding or NULL for docroot
 */
void *FindElementWithName(xml_data *data, void *node, const char *nodeName) {
	xmlNodePtr cur = node ? node : (xmlNodePtr) data->root;
	cur = cur->xmlChildrenNode;
	while (cur != NULL) {
		if ((!xmlStrcmp(cur->name, (const xmlChar *) nodeName))) {
			return (void *) cur;
		}
		xmlNodePtr nodef = (xmlNodePtr) FindElementWithName(data, cur,
				nodeName);
		if (nodef) {
			return (void *) nodef;
		}
		cur = cur->next;
	}
	return NULL;
}
Example #4
0
/*
 * finds element with name nodeName and attrName with attrValue
 * in parsed data. NULL if nothing found. node - root elemnt for
 * node finding or NULL for docroot
 */
void *FindElementWithNameAndAttr(xml_data *data, void *node, const char *nodeName,
		const char *attrName, const char *attrValue) {
	xmlNodePtr cur = node ? node : (xmlNodePtr) data->root;
	cur = cur->xmlChildrenNode;
	while (cur != NULL) {
		if ((!xmlStrcmp(cur->name, (const xmlChar *) nodeName))) {
			const char *attr = getElemAttr(cur, attrName);
			if (attr && !strcmp(attr, attrValue)){
				releaseElemValue(attr);
				return cur;
			}
			releaseElemValue(attr);
		}
		xmlNodePtr nodef = (xmlNodePtr) FindElementWithName(data, cur,
				nodeName);
		if (nodef) {
			return (void *) nodef;
		}
		cur = cur->next;
	}
	return NULL;
}