void XMLConfiguration::setRaw(const std::string& key, const std::string& value)
{
	std::string::const_iterator it = key.begin();
	Poco::XML::Node* pNode = findNode(it, key.end(), _pRoot, true);
	if (pNode)
	{
        unsigned short nodeType = pNode->nodeType();
        if (Poco::XML::Node::ATTRIBUTE_NODE == nodeType)
        {
            pNode->setNodeValue(value);
        }
        else if (Poco::XML::Node::ELEMENT_NODE == nodeType)
        {
            Poco::XML::Node* pChildNode = pNode->firstChild();
            if (pChildNode)
            {
                if (Poco::XML::Node::TEXT_NODE == pChildNode->nodeType())
                {
                    pChildNode->setNodeValue(value);
                }
            }
            else
            {
				Poco::AutoPtr<Poco::XML::Node> pText = _pDocument->createTextNode(value);
				pNode->appendChild(pText);
            }
        }
	}
    else throw NotFoundException("Node not found in XMLConfiguration", key);
}
void XMLConfiguration::removeRaw(const std::string& key)
{
	Poco::XML::Node* pNode = findNode(key);

	if (pNode)
	{
		if (pNode->nodeType() == Poco::XML::Node::ELEMENT_NODE)
		{
			Poco::XML::Node* pParent = pNode->parentNode();
			if (pParent)
			{
				pParent->removeChild(pNode);
			}
		}
		else if (pNode->nodeType() == Poco::XML::Node::ATTRIBUTE_NODE)
		{
			Poco::XML::Attr* pAttr = dynamic_cast<Poco::XML::Attr*>(pNode);
			Poco::XML::Element* pOwner = pAttr->ownerElement();
			if (pOwner)
			{
				pOwner->removeAttributeNode(pAttr);
			}
		}
	}
}
Poco::XML::Node* XMLConfiguration::findElement(const std::string& name, Poco::XML::Node* pNode, bool create)
{
	Poco::XML::Node* pChild = pNode->firstChild();
	while (pChild)
	{
		if (pChild->nodeType() == Poco::XML::Node::ELEMENT_NODE && pChild->nodeName() == name)
			return pChild;
		pChild = pChild->nextSibling();
	}
	if (create)
	{
		Poco::AutoPtr<Poco::XML::Element> pElem = pNode->ownerDocument()->createElement(name);
		pNode->appendChild(pElem);
		return pElem;
	}
	else return 0;
}
Пример #4
0
Expression::Pointer
StandardElementHandler::Create(ExpressionConverter* converter, Poco::XML::Element* element)
{
    std::string name= element->nodeName();
    if (ExpressionTagNames::INSTANCEOF == name) {
        Expression::Pointer result(new InstanceofExpression(element));
        return result;
    } else if (ExpressionTagNames::TEST == name) {
        Expression::Pointer result(new TestExpression(element));
        return result;
    } else if (ExpressionTagNames::OR == name) {
        CompositeExpression::Pointer result(new OrExpression());
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::AND == name) {
        CompositeExpression::Pointer result(new AndExpression());
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::NOT == name) {
        Poco::XML::Node* child = element->firstChild();
        while (child != 0) {
            if (child->nodeType() == Poco::XML::Node::ELEMENT_NODE) {
                Expression::Pointer result(new NotExpression(converter->Perform(static_cast<Poco::XML::Element*>(child))));
                return result;
            }
            child = child->nextSibling();
        }
    } else if (ExpressionTagNames::WITH == name) {
        CompositeExpression::Pointer result(new WithExpression(element));
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::ADAPT == name) {
        CompositeExpression::Pointer result(new AdaptExpression(element));
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::ITERATE == name) {
        CompositeExpression::Pointer result(new IterateExpression(element));
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::COUNT == name) {
        Expression::Pointer result(new CountExpression(element));
        return result;
    } else if (ExpressionTagNames::SYSTEM_TEST == name) {
        Expression::Pointer result(new SystemTestExpression(element));
        return result;
    } else if (ExpressionTagNames::RESOLVE == name) {
        CompositeExpression::Pointer result(new ResolveExpression(element));
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::ENABLEMENT == name) {
        CompositeExpression::Pointer result(new EnablementExpression(element));
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::EQUALS == name) {
        Expression::Pointer result(new EqualsExpression(element));
        return result;
    } else if (ExpressionTagNames::REFERENCE == name) {
        Expression::Pointer result(new ReferenceExpression(element));
        return result;
    }
    return Expression::Pointer();
}