void MyHandler::startElement(const Poco::XML::XMLString& namespaceURI, const Poco::XML::XMLString& localName, const Poco::XML::XMLString& qname, const Poco::XML::Attributes& attributes) { // We have reached the actual weather data in the xml string. if (qname == "measurementSiteTable") { location_data = true; } // Set counter to zero. When counter reaches three the current qname value is used as key. if (qname == "measurementSiteName" && location_data) { counter = 0; } if (location_data) { ++counter; } // Get id of site. if (qname == "measurementSiteRecord") { if (attributes.getLength()) { x = attributes.getLength(); for (int i = 0; i < x; ++i) { if (attributes.getQName(i) == "id") { _site_id = attributes.getValue(i); // std::cout << "site id: " << _site_id << std::endl; } } } } // Get latitude and longitude. if (qname == "latitude") { _lat = true; } if (qname == "longitude") { _lon = true; } }
void VSXMLWriter::startElement(const Poco::XML::XMLString& namespaceURI, const Poco::XML::XMLString& localName, const Poco::XML::XMLString& qname, const Poco::XML::Attributes& attributes) { if (!_tagClosed.back()) { _ostr << ">\r\n"; _tagClosed.back() = true; } indent(); ++_indent; _ostr << "<" << qname; if (attributes.getLength() > 0) { Poco::XML::AttributesImpl sortedAttributes; if (qname == "VisualStudioProject") { sortedAttributes.addAttribute("", "", "Name", "CDATA", attributes.getValue("Name")); sortedAttributes.addAttribute("", "", "Version", "CDATA", attributes.getValue("Version")); sortedAttributes.addAttribute("", "", "ProjectType", "CDATA", attributes.getValue("ProjectType")); sortedAttributes.addAttribute("", "", "ProjectGUID", "CDATA", attributes.getValue("ProjectGUID")); sortedAttributes.addAttribute("", "", "RootNamespace", "CDATA", attributes.getValue("RootNamespace")); sortedAttributes.addAttribute("", "", "Keyword", "CDATA", attributes.getValue("Keyword")); } else { if (attributes.getIndex("Name") != -1) { sortedAttributes.addAttribute("", "", "Name", "CDATA", attributes.getValue("Name")); } for (int i = 0; i < attributes.getLength(); i++) { if (attributes.getQName(i) != "Name") { std::string value = attributes.getValue(i); if (_convertBool && (value == "true" || value == "false")) value = Poco::toUpper(value); sortedAttributes.addAttribute(attributes.getURI(i), attributes.getLocalName(i), attributes.getQName(i), attributes.getType(i), value); } } } for (int i = 0; i < sortedAttributes.getLength(); i++) { _ostr << "\r\n"; indent(); _ostr << sortedAttributes.getQName(i) << "=\""; std::string value = sortedAttributes.getValue(i); for (Poco::XML::XMLString::const_iterator itv = value.begin(); itv != value.end(); ++itv) { char c = *itv; switch (c) { case '"': _ostr << """; break; case '\'': _ostr << "'"; break; case '&': _ostr << "&"; break; case '<': _ostr << "<"; break; case '>': _ostr << ">"; break; case '\t': _ostr << "	"; break; case '\r': _ostr << "
"; break; case '\n': _ostr << "
"; break; default: _ostr << c; break; } } _ostr << "\""; } } _tagClosed.push_back(false); }