0

I am using rapidxml to generate an XML in a C ++ application:

    xml_document<> doc;
    xml_node<>* dec1 = doc.allocate_node(node_declaration);
    dec1->append_attribute(doc.allocate_attribute("version", "1.0"));
    dec1->append_attribute(doc.allocate_attribute("encoding", "utf-8"));
    doc.append_node(dec1);
    . . .

I convert this XML into a character string:

  std::string *s;
  s = new std::string;
  print(std::back_inserter(*s), doc, 0);

I then send it to a device as a byte array.

I see that the line breaks use the character 0x0A = 10 = "LF (new line)" and that in the indented lines it puts the character 0x09 = "horizontal tab".

I would need it to use instead:

  • In line breaks the characters 0x0D 0x0A = 13 10 = CR (care return) + LF (new line).
  • At the beginning of indented lines two spaces (0x20 0x20 = 32 32) for each tab.

Is it possible to configure rapidxml to do it this way?

jstechg
  • 123
  • 1
  • 2
  • 10
  • Is this for viewing or is there some downstream software not conforming to the XML standard? – Botje Aug 12 '20 at 11:22
  • I send the XML message as bytes to a hardware equipment which expects to receive as indicated. Is it possible to do it like this with rapidxml? – jstechg Aug 12 '20 at 11:51
  • Rapidxml does not support configuration of the output format, but you could create a custom output iterator that intercepts `\n` and `\t` and replaces them with what you want. You should also yell at the vendor for not supporting XML properly. – Botje Aug 12 '20 at 12:01

0 Answers0