Exemplo n.º 1
0
void xmlt::output(std::ostream &out, unsigned indent) const
{
  // 'name' needs to be set, or we produce mal-formed
  // XML.
  
  if(name=="") return;

  do_indent(out, indent);

  out << '<' << name;

  for(attributest::const_iterator
      it=attributes.begin();
      it!=attributes.end();
      it++)
  {
    // it->first needs to be non-empty
    if(it->first=="") continue;
    out << ' ' << it->first
        << '=' << '"';
    escape_attribute(it->second, out);
    out << '"';
  }

  if(elements.empty() && data.empty())
  {
    out << "/>" << "\n";
    return;
  }

  out << '>';

  if(elements.empty())
    escape(data, out);
  else
  {
    out << "\n";

    for(elementst::const_iterator
        it=elements.begin();
        it!=elements.end();
        it++)
      it->output(out, indent+2);

    do_indent(out, indent);
  }

  out << '<' << '/' << name << '>' << "\n";
}
Exemplo n.º 2
0
Arquivo: xml.cpp Projeto: danpoe/cbmc
void xmlt::output(std::ostream &out, unsigned indent) const
{
  // 'name' needs to be set, or we produce mal-formed
  // XML.

  if(name=="")
    return;

  do_indent(out, indent);

  out << '<' << name;

  for(const auto &attribute : attributes)
  {
    // it.first needs to be non-empty
    if(attribute.first.empty())
      continue;
    out << ' ' << attribute.first
        << '=' << '"';
    escape_attribute(attribute.second, out);
    out << '"';
  }

  if(elements.empty() && data.empty())
  {
    out << "/>" << "\n";
    return;
  }

  out << '>';

  if(elements.empty())
    escape(data, out);
  else
  {
    out << "\n";

    for(const auto &element : elements)
      element.output(out, indent+2);

    do_indent(out, indent);
  }

  out << '<' << '/' << name << '>' << "\n";
}