Пример #1
0
// http://thelastpcbender.blogspot.com/2008/11/introduction-to-xerces-c-domparser.html
std::string CXercesUtils::GetSubElementValues(DOMElement* e , std::vector<std::string> &excludes) 
{
	std::string value;
	DOMNodeList * Child = e-> getChildNodes();
	const XMLSize_t nc = Child->getLength();

	//now we traverse the tree, note that we use XMLSize_t instead of int
	//
	for(XMLSize_t i=0; i< nc; i++)
	{
		DOMNode* currentNode = Child->item(i);
		if(currentNode && currentNode->getNodeType() && currentNode->getNodeType() == DOMNode::ELEMENT_NODE ) 
		{
			DOMElement* currentElem = (DOMElement*) currentNode;
			std::string elemname = GetElementName(currentElem );
			if(std::find(excludes.begin(), excludes.end(), elemname) != excludes.end())
				continue;
			if(currentElem->getChildElementCount() == (XMLSize_t) 0)
			{
				value+=GetElementName(currentElem );
				value+="=";
				value+=GetElementValue(currentElem );
				value+="<br>";
			}
			// recursively add items
			else
			{
				value+=GetSubElementValues(currentElem , excludes) ;
			}
		}
	}
	return value;
}
Пример #2
0
void CXercesUtils::DumpTree (DOMNode *tree, std::string &tmp)
{
  tabs+="\t";
  if (tree != NULL)
    {
		if (tree->getNodeType () != DOMNode::ELEMENT_NODE)
			goto leave;
		DOMElement*  e = (DOMElement* ) tree;
		std::string el_name =  XMLString::transcode(tree->getNodeName());

		std::string el_value;
		if(e->getTextContent () && e->getChildElementCount() == (XMLSize_t) 0)
			el_value = XMLString::transcode(e->getTextContent ());

		tmp+=  tabs + "<"+  el_name + ">" + el_value +  "\n";

      for (DOMNode* child = tree->getFirstChild();
           child != NULL; child = child->getNextSibling())
      {
    	  DumpTree(child, tmp);
      }
		tmp+=  tabs + "</" + el_name + ">\n";
    }
  leave:
  tabs+=tabs.substr(1);
 }
Пример #3
0
// Look at Xerces XSModel to parse XSD into tree SCMPrint
void CXercesUtils::NagivateParseTree(xercesc::DOMElement* p, std::string tabs)
{
	string name;
	short age;
	tabs+="    ";
	for (DOMNode* n = p->getFirstChild ();	n != 0;	n = n->getNextSibling ())
	{
		if (n->getNodeType () != DOMNode::ELEMENT_NODE)
			continue;
		DOMElement*  e = (DOMElement* ) n;
		std::string el_name =  XMLString::transcode(n->getNodeName());

		std::string el_value;
		if(e->getTextContent () && e->getChildElementCount() == (XMLSize_t) 0)
			el_value = XMLString::transcode(e->getTextContent ());

		std::cerr <<  tabs.c_str() << el_name.c_str()<< "=" << el_value.c_str()<< endl;
		//DOMNode* node = n->getFirstChild ();

		NagivateParseTree((DOMElement*) n,tabs);
	}
	tabs=tabs.substr(1);

}