예제 #1
0
//----------------------------------------------------------------------------------------------
/// Signals start of element
void ComponentParser::startElement(const Poco::XML::XMLString &,
                                   const Poco::XML::XMLString &localName,
                                   const Poco::XML::XMLString &,
                                   const Poco::XML::Attributes &attr) {
  // Find the parent of this new component.
  Component *current = nullptr;
  if (!m_current.empty())
    current = m_current.back();

  // for (int i=0; i<attr.getLength(); i++)  std::cout << i << " : "<<
  // attr.getQName(i) << "," << attr.getLocalName(i) << std::endl;

  // Find the name in the attributes
  std::string name = attr.getValue("", "name");

  Component *newComp = nullptr;
  if (localName == "Component")
    newComp = new Component(name, current);
  else {
    // throw std::runtime_error("ComponentParser:: unexpected XML tag '" +
    // localName + "'.");
  }

  // A new component was created
  if (newComp) {
    m_current.push_back(newComp);
    // Read the attributes into the new component
    newComp->readXMLAttributes(attr);
  }
}
예제 #2
0
파일: MyHandler.cpp 프로젝트: kometen/Poco2
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;
    }
}
예제 #3
0
 void AbstractXULParser::getAttributes(const Poco::XML::Attributes & inXMLAttributes,
                                       AttributesMapping & outXULAttributes)
 {
     for (int idx = 0; idx != inXMLAttributes.getLength(); ++idx)
     {
         const Poco::XML::XMLString & name = inXMLAttributes.getLocalName(idx);
         const Poco::XML::XMLString & value = inXMLAttributes.getValue(idx);
         outXULAttributes[name] = value;
     }
 }
예제 #4
0
	void ForecastParser::startElement(const Poco::XML::XMLString& namespaceURI, const Poco::XML::XMLString& localName, const Poco::XML::XMLString& qname,
			const Poco::XML::Attributes& attributes) {

		static std::map <int, int> hmap = hourMap();

		if (localName == "time"){
			int tz = 0;
			data.dateStr =  attributes.getValue("", "from");
			std::cout << data.dateStr << std::endl;
			Poco::DateTime dt;
			Poco::DateTimeParser::parse(data.dateStr, dt, tz);
			data.date = Poco::DateTime(
					dt.year(),
					dt.month(),
					dt.day(),
					hmap[dt.hour()]
			);
		}
		if (localName == "temperature"){
			data.temperature = Poco::NumberParser::parse(attributes.getValue("", "value"));
		}
		if (localName == "symbol"){
			data.img = Poco::NumberParser::parse(attributes.getValue("", "number"));
			data.info = attributes.getValue("", "name");
		}
		if (localName == "windSpeed"){
			data.wind = Poco::NumberParser::parseFloat(attributes.getValue("", "mps"));
		}
		if (localName == "precipitation"){
			data.precipitation = Poco::NumberParser::parseFloat(attributes.getValue("", "value"));
		}
	}
예제 #5
0
	void startElement(const Poco::XML::XMLString& uri, const Poco::XML::XMLString& localName, const Poco::XML::XMLString& qname, const Poco::XML::Attributes& attributes)
	{
		where("startElement");
		m_Msg.Message(Poco::format("    uri:       %s", uri));
		m_Msg.Message(Poco::format("    localName: %s", localName));
		m_Msg.Message(Poco::format("    qname:     %s", qname));
		if(0 != attributes.getLength())
		{
			m_Msg.Message("    Attributes: ");
			for(int i=0; i<attributes.getLength(); ++i)
			{
				m_Msg.Message(Poco::format("     %s=\"%s\"", attributes.getLocalName(i), attributes.getValue(i)));
			}
		}
	}
예제 #6
0
파일: VSXMLWriter.cpp 프로젝트: 12307/poco
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 << "&quot;"; break;
				case '\'': _ostr << "&apos;"; break;
				case '&':  _ostr << "&amp;"; break;
				case '<':  _ostr << "&lt;"; break;
				case '>':  _ostr << "&gt;"; break;
				case '\t': _ostr << "&#x9;"; break;
				case '\r': _ostr << "&#xD;"; break;
				case '\n': _ostr << "&#xA;"; break;
				default:   _ostr << c; break;
				}
			}
			_ostr << "\"";
		}
	}
	_tagClosed.push_back(false);
}