コード例 #1
0
void dump(CXMLElementx *root,  int *indent)
{
	for (int i = 0 ; i < *indent; i++)
		cout << '\t';

	if (root->m_nTagLen < 0)
		root->m_nTagLen = root->m_nTagLen;

	cout.write(root->m_tag, root->m_nTagLen);
	cout << "=";
	cout.write(root->m_value, root->m_nValueLen);
	cout << " { ";
	dump(root->getAttributes() );
	cout	<< "}" << endl;
	(*indent)++;

	if (root->getChildren())
	{
		CListIterator itChildren(root->getChildren());
		while (!itChildren)
		{
			dump((CXMLElementx *)itChildren++, indent);
		}
	}
	(*indent)--;
}
コード例 #2
0
bool ofxXivelyOutput::parseResponseEeml(string _response) {
	if (bVerbose) printf("[Xively] start parsing eeml\n");
	try
	{
		pData.clear();
		DOMParser parser;
		AttrMap* pMap;
		AutoPtr<Document> pDoc = parser.parseMemory(_response.c_str(), _response.length());

		NodeIterator itElem(pDoc, NodeFilter::SHOW_ELEMENT);

		Node* pNode = itElem.nextNode();
		while (pNode)
		{
			if (pNode->nodeName() == XMLString("environment"))
			{
				pMap = (AttrMap*) pNode->attributes();
				sUpdated = pMap->getNamedItem("updated")->nodeValue();
			}

			if (pNode->nodeName() == XMLString("title"))
				sTitle = pNode->firstChild()->getNodeValue();
			if (pNode->nodeName() == XMLString("status"))
				sStatus = pNode->firstChild()->getNodeValue();
			if (pNode->nodeName() == XMLString("description"))
				sDescription = pNode->firstChild()->getNodeValue();
			if (pNode->nodeName() == XMLString("website"))
				sWebsite = pNode->firstChild()->getNodeValue();

			if (pNode->nodeName() == XMLString("location"))
			{
				//				pMap = (AttrMap*)pNode->attributes();
				//				location.sDomain = pMap->getNamedItem("domain")->nodeValue();
				//				location.sExposure = pMap->getNamedItem("exposure")->nodeValue();
				//				location.sDisposition = pMap->getNamedItem("disposition")->nodeValue();

				NodeIterator itChildren(pNode, NodeFilter::SHOW_ELEMENT);
				Node* pChild = itChildren.nextNode();
				while (pChild)
				{
					if (pChild->nodeName() == XMLString("name"))
						location.sName = pChild->firstChild()->nodeValue();
					if (pChild->nodeName() == XMLString("lat"))
						location.sLat = pChild->firstChild()->nodeValue();
					if (pChild->nodeName() == XMLString("lon"))
						location.sLon = pChild->firstChild()->nodeValue();

					pChild = itChildren.nextNode();
				}
			}

			if (pNode->nodeName() == XMLString("data"))
			{
				ofxXivelyData data;

				pMap = (AttrMap*) pNode->attributes();
				data.iId = atoi(pMap->getNamedItem("id")->nodeValue().c_str());

				NodeIterator itChildren(pNode, NodeFilter::SHOW_ELEMENT);
				Node* pChild = itChildren.nextNode();
				while (pChild)
				{
					if (pChild->nodeName() == XMLString("tag"))
						data.pTags.push_back(pChild->firstChild()->getNodeValue());

					if (pChild->nodeName() == XMLString("value"))
					{
						data.fValue = atof(pChild->firstChild()->getNodeValue().c_str());

						pMap = (AttrMap*) pChild->attributes();
						data.fValueMin = atof(pMap->getNamedItem("minValue")->nodeValue().c_str());
						data.fValueMax = atof(pMap->getNamedItem("maxValue")->nodeValue().c_str());
					}

					pChild = itChildren.nextNode();
				}

				pData.push_back(data);
			}

			pNode = itElem.nextNode();
		}
	}
	catch (Exception& exc)
	{
		printf("[Xively] Parse xml exception: %s\n", exc.displayText().c_str());
		return false;
	}
	if (bVerbose) printf("[Xively] finished parsing eeml\n");

	return true;
}