Ejemplo n.º 1
0
QString XMLConfig::attr(const DOMNode *pParentNode, const QString &sNodeName, const QString &sAttrName, const QString &sAttrValue, const QString &sFAttrName ) const {

	if(!pParentNode) throw ex_base(ex_base::error, "empty node", "XMLConfig::attr");

	const DOMNode *pNode = pParentNode->getFirstChild();
	const DOMNode *pFindedNode = 0;
	while(pNode) {
		if( pNode->getNodeType() == DOMNode::ELEMENT_NODE && toQString(pNode->getNodeName()) == sNodeName ) {
			const DOMNode *pAttrNode = getNodeAttribute( pNode, sAttrName );
			if( pAttrNode && toQString(pAttrNode->getNodeValue()) == sAttrValue ) {
				pFindedNode = getNodeAttribute( pNode, sFAttrName );
				break;
			}
		}
		pNode = pNode->getNextSibling();
	}

	if( !pFindedNode )
		throw ex_base(ex_base::error,
					  QString("No such attribute '%1' in node '%2' with attr '%3 = %4' in file '%5'")
							.arg(sFAttrName)
							.arg(sNodeName)
							.arg(sAttrName)
							.arg(sAttrValue)
							.arg(m_strFileName.data()), 
					  "XMLConfig::attr");

	return toQString( pFindedNode->getNodeValue() );
}
Ejemplo n.º 2
0
int CUtil::getNodeIntAttribute(DOMNode *node, char *attrName)
{
    char *attrValue = getNodeAttribute(node, attrName);
    int ret         = atoi(attrValue);
    //free(attrValue);
    return ret;
}
Ejemplo n.º 3
0
bool XMLConfig::isAttr(const DOMNode *pNode, const QString &sAttrName) const {

	if(!pNode) throw ex_base(ex_base::error, "empty node", "XMLConfig::getNodeAttributeValue");

	DOMNode *pAttrNode = getNodeAttribute(pNode, sAttrName);

	if(!pAttrNode) return false;

	return true;
}
Ejemplo n.º 4
0
QString XMLConfig::attr(const DOMNode *pNode, const QString &sAttrName) const {

	if(!pNode) throw ex_base(ex_base::error, QString("empty node").arg(sAttrName), "XMLConfig::attr(pNode, sAttrName)");

	DOMNode *pAttrNode = getNodeAttribute(pNode, sAttrName);

	if(!pAttrNode)
		throw ex_base(ex_base::error, 
					  QString("No such attribute '%1' in node '%2' in file '%3'")
							.arg(sAttrName)
							.arg(toQString(pNode->getNodeName()))
							.arg(m_strFileName.data()), 
					  "XMLConfig::getNodeAttributeValue");

	return toQString(pAttrNode->getNodeValue());
}
Ejemplo n.º 5
0
const DOMNode* XMLConfig::find(const DOMNode *pParentNode, const QString &sNodeFName, const QString &sAttrNameForSearch) {

	const DOMNode *pFindedNode = 0;
	DOMNode *pNode = pParentNode->getFirstChild();

	QString sCurName;
	if(sNodeFName.contains(":"))
		sCurName = sNodeFName.left(sNodeFName.indexOf(":"));
	else
		sCurName = sNodeFName;

	while(pNode) {

		if(pNode->getNodeType() == DOMNode::ELEMENT_NODE) {

			bool bFinded = false;
			if(sAttrNameForSearch.isEmpty()) { 
				if(toQString(pNode->getNodeName()) == sCurName) bFinded = true;
			}
			else {
				DOMNode *pAttrNode = getNodeAttribute(pNode, sAttrNameForSearch);
				if(pAttrNode && toQString(pAttrNode->getNodeValue()) == sCurName) bFinded = true;
			}

			if(bFinded) {

				if(sNodeFName.contains(":")) {

					pFindedNode = find(pNode, sNodeFName.right(sNodeFName.length() - sNodeFName.indexOf(":") - 1), sAttrNameForSearch);
					if(pFindedNode) break;
				}
				else {
					pFindedNode = pNode;
					break;
				}
			}
		}

		pNode = pNode->getNextSibling();
	}

	return pFindedNode;
}