74{
75 ostringstream oss;
76
81
84
86
87 const char* piData = "version=\"1.0\" encoding=\"UTF-8\"";
88 writer.processingInstruction("xml", piData);
89
91
93 attributes.push_back(make_pair("name1", "value1"));
94 attributes.push_back(make_pair("name2", "420"));
95 attributes.push_back(make_pair("name3", "0.666"));
96 writer.startElement("root", attributes);
97
100
101 attributes.clear();
102 attributes.push_back(make_pair("name", "nixon"));
103 attributes.push_back(make_pair("color", "red"));
104 attributes.push_back(make_pair("number", "37"));
105 writer.pushStyle(XMLWriter::StyleFlag_AttributesOnMultipleLines);
106 writer.startElement("record", attributes);
107 writer.pushStyle(XMLWriter::StyleFlag_InlineInner);
108 writer.startElement("quote");
109 writer.characters("I'm not a crook.");
110 writer.endElement();
112 writer.popStyle();
113 writer.endElement();
114 writer.popStyle();
115
116 attributes.clear();
117 attributes.push_back(make_pair("name", "\"Penn & Teller\""));
118 writer.startElement("record", attributes);
119 writer.pushStyle(XMLWriter::StyleFlag_InlineInner);
120 writer.startElement("quote");
121 writer.characters("'Bull<shit!'");
122 writer.endElement();
123 writer.popStyle();
124 writer.endElement();
125
126 attributes.clear();
127 attributes.push_back(make_pair("name", "clinton"));
128 attributes.push_back(make_pair("color", "blue"));
129 attributes.push_back(make_pair("number", "42"));
130 writer.pushStyle(XMLWriter::StyleFlag_AttributesOnMultipleLines);
131 writer.startElement("record", attributes);
132 writer.pushStyle(XMLWriter::StyleFlag_InlineInner);
133 writer.startElement("quote");
134 writer.characters("I did ");
135 writer.pushStyle(XMLWriter::StyleFlag_Inline);
136 unit_assert(writer.position() == writer.positionNext());
137 writer.startElement("em");
138 writer.characters("not");
139 writer.endElement();
140 writer.popStyle();
141 writer.characters(" have sexual relations with that woman.");
142 writer.endElement();
143 writer.popStyle();
145 writer.endElement();
146 writer.popStyle();
147
148 attributes.clear();
149 attributes.push_back(make_pair("name", "bush"));
150 attributes.push_back(make_pair("color", "red"));
151 attributes.push_back(make_pair("number", "43"));
152 writer.pushStyle(XMLWriter::StyleFlag_AttributesOnMultipleLines);
153 writer.startElement("record", attributes);
154 writer.pushStyle(XMLWriter::StyleFlag_InlineInner);
155 writer.startElement("quote");
156 writer.characters("Mission accomplished.");
157 writer.endElement();
158 writer.popStyle();
159 writer.endElement();
160 writer.popStyle();
161
162 writer.endElement();
163
164 if (
os_) *
os_ <<
"test: (" << oss.str().size() <<
")\n" << oss.str() << endl;
165
167 unit_assert(writer.position() == (
int)oss.str().size());
169
170 if (
os_) *
os_ <<
"outputObserver cache:\n" << outputObserver.
cache << endl;
172
173
174
175
176 string id1("1invalid ID");
180
181 string id2("_invalid-ID_#2_<3>");
184
185 string crazyId("!!!");
187}
vector of name/value pairs to be written as XML attributes
The XMLWriter class provides simple, tag-level XML syntax writing.
PWIZ_API_DECL std::string encode_xml_id_copy(const std::string &str)
Encodes any characters not suitable in an xml:ID or xml:IDREF with their hexadecimal value,...
PWIZ_API_DECL std::string & encode_xml_id(std::string &str)
Encodes any characters not suitable in an xml:ID or xml:IDREF with their hexadecimal value,...
initial configuration of the XMLWriter
OutputObserver * outputObserver
unsigned int indentationStep