View Javadoc
1   package ca.uhn.fhir.util;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.context.ConfigurationException;
24  import ca.uhn.fhir.model.primitive.XhtmlDt;
25  import ca.uhn.fhir.parser.DataFormatException;
26  import ca.uhn.fhir.util.jar.DependencyLogFactory;
27  import ca.uhn.fhir.util.jar.IDependencyLog;
28  import com.ctc.wstx.api.WstxInputProperties;
29  import com.ctc.wstx.stax.WstxOutputFactory;
30  import org.apache.commons.lang3.StringEscapeUtils;
31  import org.codehaus.stax2.XMLOutputFactory2;
32  import org.codehaus.stax2.io.EscapingWriterFactory;
33  
34  import javax.xml.stream.*;
35  import javax.xml.stream.events.XMLEvent;
36  import java.io.*;
37  import java.util.*;
38  
39  import static org.apache.commons.lang3.StringUtils.isBlank;
40  
41  /**
42   * Utility methods for working with the StAX API.
43   * 
44   * This class contains code adapted from the Apache Axiom project.
45   */
46  public class XmlUtil {
47  	private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(XmlUtil.class);
48  	private static final Map<String, Integer> VALID_ENTITY_NAMES;
49  	private static final ExtendedEntityReplacingXmlResolver XML_RESOLVER = new ExtendedEntityReplacingXmlResolver();
50  	private static XMLOutputFactory ourFragmentOutputFactory;
51  	private static volatile boolean ourHaveLoggedStaxImplementation;
52  	private static volatile XMLInputFactory ourInputFactory;
53  	private static Throwable ourNextException;
54  	private static volatile XMLOutputFactory ourOutputFactory;
55  
56  	static {
57  		HashMap<String, Integer> validEntityNames = new HashMap<String, Integer>(1448);
58  		validEntityNames.put("AElig", 0x000C6);
59  		validEntityNames.put("Aacute", 0x000C1);
60  		validEntityNames.put("Abreve", 0x00102);
61  		validEntityNames.put("Acirc", 0x000C2);
62  		validEntityNames.put("Acy", 0x00410);
63  		validEntityNames.put("Afr", 0x1D504);
64  		validEntityNames.put("Agrave", 0x000C0);
65  		validEntityNames.put("Alpha", 0x00391);
66  		validEntityNames.put("Amacr", 0x00100);
67  		validEntityNames.put("And", 0x02A53);
68  		validEntityNames.put("Aogon", 0x00104);
69  		validEntityNames.put("Aopf", 0x1D538);
70  		validEntityNames.put("ApplyFunction", 0x02061);
71  		validEntityNames.put("Aring", 0x000C5);
72  		validEntityNames.put("Ascr", 0x1D49C);
73  		validEntityNames.put("Atilde", 0x000C3);
74  		validEntityNames.put("Auml", 0x000C4);
75  		validEntityNames.put("Barv", 0x02AE7);
76  		validEntityNames.put("Barwed", 0x02306);
77  		validEntityNames.put("Bcy", 0x00411);
78  		validEntityNames.put("Beta", 0x00392);
79  		validEntityNames.put("Bfr", 0x1D505);
80  		validEntityNames.put("Bopf", 0x1D539);
81  		validEntityNames.put("CHcy", 0x00427);
82  		validEntityNames.put("Cacute", 0x00106);
83  		validEntityNames.put("Cap", 0x022D2);
84  		validEntityNames.put("CapitalDifferentialD", 0x02145);
85  		validEntityNames.put("Ccaron", 0x0010C);
86  		validEntityNames.put("Ccedil", 0x000C7);
87  		validEntityNames.put("Ccirc", 0x00108);
88  		validEntityNames.put("Cconint", 0x02230);
89  		validEntityNames.put("Cdot", 0x0010A);
90  		validEntityNames.put("Cfr", 0x0212D);
91  		validEntityNames.put("Chi", 0x003A7);
92  		validEntityNames.put("Colon", 0x02237);
93  		validEntityNames.put("Colone", 0x02A74);
94  		validEntityNames.put("Conint", 0x0222F);
95  		validEntityNames.put("Copf", 0x02102);
96  		validEntityNames.put("Cross", 0x02A2F);
97  		validEntityNames.put("Cscr", 0x1D49E);
98  		validEntityNames.put("Cup", 0x022D3);
99  		validEntityNames.put("DDotrahd", 0x02911);
100 		validEntityNames.put("DJcy", 0x00402);
101 		validEntityNames.put("DScy", 0x00405);
102 		validEntityNames.put("DZcy", 0x0040F);
103 		validEntityNames.put("Dagger", 0x02021);
104 		validEntityNames.put("Darr", 0x021A1);
105 		validEntityNames.put("Dashv", 0x02AE4);
106 		validEntityNames.put("Dcaron", 0x0010E);
107 		validEntityNames.put("Dcy", 0x00414);
108 		validEntityNames.put("Delta", 0x00394);
109 		validEntityNames.put("Dfr", 0x1D507);
110 		validEntityNames.put("DifferentialD", 0x02146);
111 		validEntityNames.put("Dopf", 0x1D53B);
112 		validEntityNames.put("Dot", 0x000A8);
113 		validEntityNames.put("DotDot", 0x020DC);
114 		validEntityNames.put("DownArrowBar", 0x02913);
115 		validEntityNames.put("DownBreve", 0x00311);
116 		validEntityNames.put("DownLeftRightVector", 0x02950);
117 		validEntityNames.put("DownLeftTeeVector", 0x0295E);
118 		validEntityNames.put("DownLeftVectorBar", 0x02956);
119 		validEntityNames.put("DownRightTeeVector", 0x0295F);
120 		validEntityNames.put("DownRightVectorBar", 0x02957);
121 		validEntityNames.put("DownTeeArrow", 0x021A7);
122 		validEntityNames.put("Dscr", 0x1D49F);
123 		validEntityNames.put("Dstrok", 0x00110);
124 		validEntityNames.put("ENG", 0x0014A);
125 		validEntityNames.put("ETH", 0x000D0);
126 		validEntityNames.put("Eacute", 0x000C9);
127 		validEntityNames.put("Ecaron", 0x0011A);
128 		validEntityNames.put("Ecirc", 0x000CA);
129 		validEntityNames.put("Ecy", 0x0042D);
130 		validEntityNames.put("Edot", 0x00116);
131 		validEntityNames.put("Efr", 0x1D508);
132 		validEntityNames.put("Egrave", 0x000C8);
133 		validEntityNames.put("Emacr", 0x00112);
134 		validEntityNames.put("EmptySmallSquare", 0x025FB);
135 		validEntityNames.put("EmptyVerySmallSquare", 0x025AB);
136 		validEntityNames.put("Eogon", 0x00118);
137 		validEntityNames.put("Eopf", 0x1D53C);
138 		validEntityNames.put("Epsilon", 0x00395);
139 		validEntityNames.put("Equal", 0x02A75);
140 		validEntityNames.put("Escr", 0x02130);
141 		validEntityNames.put("Esim", 0x02A73);
142 		validEntityNames.put("Eta", 0x00397);
143 		validEntityNames.put("Euml", 0x000CB);
144 		validEntityNames.put("ExponentialE", 0x02147);
145 		validEntityNames.put("Fcy", 0x00424);
146 		validEntityNames.put("Ffr", 0x1D509);
147 		validEntityNames.put("FilledSmallSquare", 0x025FC);
148 		validEntityNames.put("Fopf", 0x1D53D);
149 		validEntityNames.put("Fscr", 0x02131);
150 		validEntityNames.put("GJcy", 0x00403);
151 		validEntityNames.put("Gamma", 0x00393);
152 		validEntityNames.put("Gammad", 0x003DC);
153 		validEntityNames.put("Gbreve", 0x0011E);
154 		validEntityNames.put("Gcedil", 0x00122);
155 		validEntityNames.put("Gcirc", 0x0011C);
156 		validEntityNames.put("Gcy", 0x00413);
157 		validEntityNames.put("Gdot", 0x00120);
158 		validEntityNames.put("Gfr", 0x1D50A);
159 		validEntityNames.put("Gg", 0x022D9);
160 		validEntityNames.put("Gopf", 0x1D53E);
161 		validEntityNames.put("GreaterGreater", 0x02AA2);
162 		validEntityNames.put("Gscr", 0x1D4A2);
163 		validEntityNames.put("Gt", 0x0226B);
164 		validEntityNames.put("HARDcy", 0x0042A);
165 		validEntityNames.put("Hat", 0x0005E);
166 		validEntityNames.put("Hcirc", 0x00124);
167 		validEntityNames.put("Hfr", 0x0210C);
168 		validEntityNames.put("Hstrok", 0x00126);
169 		validEntityNames.put("IEcy", 0x00415);
170 		validEntityNames.put("IJlig", 0x00132);
171 		validEntityNames.put("IOcy", 0x00401);
172 		validEntityNames.put("Iacute", 0x000CD);
173 		validEntityNames.put("Icirc", 0x000CE);
174 		validEntityNames.put("Icy", 0x00418);
175 		validEntityNames.put("Idot", 0x00130);
176 		validEntityNames.put("Igrave", 0x000CC);
177 		validEntityNames.put("Imacr", 0x0012A);
178 		validEntityNames.put("ImaginaryI", 0x02148);
179 		validEntityNames.put("Int", 0x0222C);
180 		validEntityNames.put("InvisibleComma", 0x02063);
181 		validEntityNames.put("InvisibleTimes", 0x02062);
182 		validEntityNames.put("Iogon", 0x0012E);
183 		validEntityNames.put("Iopf", 0x1D540);
184 		validEntityNames.put("Iota", 0x00399);
185 		validEntityNames.put("Iscr", 0x02110);
186 		validEntityNames.put("Itilde", 0x00128);
187 		validEntityNames.put("Iukcy", 0x00406);
188 		validEntityNames.put("Iuml", 0x000CF);
189 		validEntityNames.put("Jcirc", 0x00134);
190 		validEntityNames.put("Jcy", 0x00419);
191 		validEntityNames.put("Jfr", 0x1D50D);
192 		validEntityNames.put("Jopf", 0x1D541);
193 		validEntityNames.put("Jscr", 0x1D4A5);
194 		validEntityNames.put("Jsercy", 0x00408);
195 		validEntityNames.put("Jukcy", 0x00404);
196 		validEntityNames.put("KHcy", 0x00425);
197 		validEntityNames.put("KJcy", 0x0040C);
198 		validEntityNames.put("Kappa", 0x0039A);
199 		validEntityNames.put("Kcedil", 0x00136);
200 		validEntityNames.put("Kcy", 0x0041A);
201 		validEntityNames.put("Kfr", 0x1D50E);
202 		validEntityNames.put("Kopf", 0x1D542);
203 		validEntityNames.put("Kscr", 0x1D4A6);
204 		validEntityNames.put("LJcy", 0x00409);
205 		validEntityNames.put("Lacute", 0x00139);
206 		validEntityNames.put("Lambda", 0x0039B);
207 		validEntityNames.put("Lang", 0x027EA);
208 		validEntityNames.put("Larr", 0x0219E);
209 		validEntityNames.put("Lcaron", 0x0013D);
210 		validEntityNames.put("Lcedil", 0x0013B);
211 		validEntityNames.put("Lcy", 0x0041B);
212 		validEntityNames.put("LeftDownTeeVector", 0x02961);
213 		validEntityNames.put("LeftDownVectorBar", 0x02959);
214 		validEntityNames.put("LeftRightVector", 0x0294E);
215 		validEntityNames.put("LeftTeeArrow", 0x021A4);
216 		validEntityNames.put("LeftTeeVector", 0x0295A);
217 		validEntityNames.put("LeftTriangleBar", 0x029CF);
218 		validEntityNames.put("LeftUpDownVector", 0x02951);
219 		validEntityNames.put("LeftUpTeeVector", 0x02960);
220 		validEntityNames.put("LeftUpVectorBar", 0x02958);
221 		validEntityNames.put("LeftVectorBar", 0x02952);
222 		validEntityNames.put("LessLess", 0x02AA1);
223 		validEntityNames.put("Lfr", 0x1D50F);
224 		validEntityNames.put("Ll", 0x022D8);
225 		validEntityNames.put("Lmidot", 0x0013F);
226 		validEntityNames.put("Lopf", 0x1D543);
227 		validEntityNames.put("Lscr", 0x02112);
228 		validEntityNames.put("Lstrok", 0x00141);
229 		validEntityNames.put("Lt", 0x0226A);
230 		validEntityNames.put("Map", 0x02905);
231 		validEntityNames.put("Mcy", 0x0041C);
232 		validEntityNames.put("MediumSpace", 0x0205F);
233 		validEntityNames.put("Mfr", 0x1D510);
234 		validEntityNames.put("Mopf", 0x1D544);
235 		validEntityNames.put("Mu", 0x0039C);
236 		validEntityNames.put("NJcy", 0x0040A);
237 		validEntityNames.put("Nacute", 0x00143);
238 		validEntityNames.put("Ncaron", 0x00147);
239 		validEntityNames.put("Ncedil", 0x00145);
240 		validEntityNames.put("Ncy", 0x0041D);
241 		validEntityNames.put("NewLine", 0x0000A);
242 		validEntityNames.put("Nfr", 0x1D511);
243 		validEntityNames.put("NoBreak", 0x02060);
244 		validEntityNames.put("Nopf", 0x02115);
245 		validEntityNames.put("Not", 0x02AEC);
246 		validEntityNames.put("NotCupCap", 0x0226D);
247 		validEntityNames.put("Nscr", 0x1D4A9);
248 		validEntityNames.put("Ntilde", 0x000D1);
249 		validEntityNames.put("Nu", 0x0039D);
250 		validEntityNames.put("OElig", 0x00152);
251 		validEntityNames.put("Oacute", 0x000D3);
252 		validEntityNames.put("Ocirc", 0x000D4);
253 		validEntityNames.put("Ocy", 0x0041E);
254 		validEntityNames.put("Odblac", 0x00150);
255 		validEntityNames.put("Ofr", 0x1D512);
256 		validEntityNames.put("Ograve", 0x000D2);
257 		validEntityNames.put("Omacr", 0x0014C);
258 		validEntityNames.put("Omega", 0x003A9);
259 		validEntityNames.put("Omicron", 0x0039F);
260 		validEntityNames.put("Oopf", 0x1D546);
261 		validEntityNames.put("Or", 0x02A54);
262 		validEntityNames.put("Oscr", 0x1D4AA);
263 		validEntityNames.put("Oslash", 0x000D8);
264 		validEntityNames.put("Otilde", 0x000D5);
265 		validEntityNames.put("Otimes", 0x02A37);
266 		validEntityNames.put("Ouml", 0x000D6);
267 		validEntityNames.put("OverBrace", 0x023DE);
268 		validEntityNames.put("OverParenthesis", 0x023DC);
269 		validEntityNames.put("Pcy", 0x0041F);
270 		validEntityNames.put("Pfr", 0x1D513);
271 		validEntityNames.put("Phi", 0x003A6);
272 		validEntityNames.put("Pi", 0x003A0);
273 		validEntityNames.put("Popf", 0x02119);
274 		validEntityNames.put("Pr", 0x02ABB);
275 		validEntityNames.put("Prime", 0x02033);
276 		validEntityNames.put("Pscr", 0x1D4AB);
277 		validEntityNames.put("Psi", 0x003A8);
278 		validEntityNames.put("Qfr", 0x1D514);
279 		validEntityNames.put("Qscr", 0x1D4AC);
280 		validEntityNames.put("RBarr", 0x02910);
281 		validEntityNames.put("Racute", 0x00154);
282 		validEntityNames.put("Rang", 0x027EB);
283 		validEntityNames.put("Rarr", 0x021A0);
284 		validEntityNames.put("Rarrtl", 0x02916);
285 		validEntityNames.put("Rcaron", 0x00158);
286 		validEntityNames.put("Rcedil", 0x00156);
287 		validEntityNames.put("Rcy", 0x00420);
288 		validEntityNames.put("Rho", 0x003A1);
289 		validEntityNames.put("RightDownTeeVector", 0x0295D);
290 		validEntityNames.put("RightDownVectorBar", 0x02955);
291 		validEntityNames.put("RightTeeVector", 0x0295B);
292 		validEntityNames.put("RightTriangleBar", 0x029D0);
293 		validEntityNames.put("RightUpDownVector", 0x0294F);
294 		validEntityNames.put("RightUpTeeVector", 0x0295C);
295 		validEntityNames.put("RightUpVectorBar", 0x02954);
296 		validEntityNames.put("RightVectorBar", 0x02953);
297 		validEntityNames.put("RoundImplies", 0x02970);
298 		validEntityNames.put("Rscr", 0x0211B);
299 		validEntityNames.put("RuleDelayed", 0x029F4);
300 		validEntityNames.put("SHCHcy", 0x00429);
301 		validEntityNames.put("SHcy", 0x00428);
302 		validEntityNames.put("SOFTcy", 0x0042C);
303 		validEntityNames.put("Sacute", 0x0015A);
304 		validEntityNames.put("Sc", 0x02ABC);
305 		validEntityNames.put("Scaron", 0x00160);
306 		validEntityNames.put("Scedil", 0x0015E);
307 		validEntityNames.put("Scirc", 0x0015C);
308 		validEntityNames.put("Scy", 0x00421);
309 		validEntityNames.put("Sfr", 0x1D516);
310 		validEntityNames.put("Sigma", 0x003A3);
311 		validEntityNames.put("Sopf", 0x1D54A);
312 		validEntityNames.put("Sscr", 0x1D4AE);
313 		validEntityNames.put("Sub", 0x022D0);
314 		validEntityNames.put("Sup", 0x022D1);
315 		validEntityNames.put("THORN", 0x000DE);
316 		validEntityNames.put("TSHcy", 0x0040B);
317 		validEntityNames.put("TScy", 0x00426);
318 		validEntityNames.put("Tab", 0x00009);
319 		validEntityNames.put("Tau", 0x003A4);
320 		validEntityNames.put("Tcaron", 0x00164);
321 		validEntityNames.put("Tcedil", 0x00162);
322 		validEntityNames.put("Tcy", 0x00422);
323 		validEntityNames.put("Tfr", 0x1D517);
324 		validEntityNames.put("Theta", 0x00398);
325 		validEntityNames.put("Topf", 0x1D54B);
326 		validEntityNames.put("Tscr", 0x1D4AF);
327 		validEntityNames.put("Tstrok", 0x00166);
328 		validEntityNames.put("Uacute", 0x000DA);
329 		validEntityNames.put("Uarr", 0x0219F);
330 		validEntityNames.put("Uarrocir", 0x02949);
331 		validEntityNames.put("Ubrcy", 0x0040E);
332 		validEntityNames.put("Ubreve", 0x0016C);
333 		validEntityNames.put("Ucirc", 0x000DB);
334 		validEntityNames.put("Ucy", 0x00423);
335 		validEntityNames.put("Udblac", 0x00170);
336 		validEntityNames.put("Ufr", 0x1D518);
337 		validEntityNames.put("Ugrave", 0x000D9);
338 		validEntityNames.put("Umacr", 0x0016A);
339 		validEntityNames.put("UnderBar", 0x00332);
340 		validEntityNames.put("UnderBrace", 0x023DF);
341 		validEntityNames.put("UnderParenthesis", 0x023DD);
342 		validEntityNames.put("Uogon", 0x00172);
343 		validEntityNames.put("Uopf", 0x1D54C);
344 		validEntityNames.put("UpArrowBar", 0x02912);
345 		validEntityNames.put("UpTeeArrow", 0x021A5);
346 		validEntityNames.put("Upsi", 0x003D2);
347 		validEntityNames.put("Upsilon", 0x003A5);
348 		validEntityNames.put("Uring", 0x0016E);
349 		validEntityNames.put("Uscr", 0x1D4B0);
350 		validEntityNames.put("Utilde", 0x00168);
351 		validEntityNames.put("Uuml", 0x000DC);
352 		validEntityNames.put("VDash", 0x022AB);
353 		validEntityNames.put("Vbar", 0x02AEB);
354 		validEntityNames.put("Vcy", 0x00412);
355 		validEntityNames.put("Vdash", 0x022A9);
356 		validEntityNames.put("Vdashl", 0x02AE6);
357 		validEntityNames.put("Verbar", 0x02016);
358 		validEntityNames.put("VerticalSeparator", 0x02758);
359 		validEntityNames.put("Vfr", 0x1D519);
360 		validEntityNames.put("Vopf", 0x1D54D);
361 		validEntityNames.put("Vscr", 0x1D4B1);
362 		validEntityNames.put("Vvdash", 0x022AA);
363 		validEntityNames.put("Wcirc", 0x00174);
364 		validEntityNames.put("Wfr", 0x1D51A);
365 		validEntityNames.put("Wopf", 0x1D54E);
366 		validEntityNames.put("Wscr", 0x1D4B2);
367 		validEntityNames.put("Xfr", 0x1D51B);
368 		validEntityNames.put("Xi", 0x0039E);
369 		validEntityNames.put("Xopf", 0x1D54F);
370 		validEntityNames.put("Xscr", 0x1D4B3);
371 		validEntityNames.put("YAcy", 0x0042F);
372 		validEntityNames.put("YIcy", 0x00407);
373 		validEntityNames.put("YUcy", 0x0042E);
374 		validEntityNames.put("Yacute", 0x000DD);
375 		validEntityNames.put("Ycirc", 0x00176);
376 		validEntityNames.put("Ycy", 0x0042B);
377 		validEntityNames.put("Yfr", 0x1D51C);
378 		validEntityNames.put("Yopf", 0x1D550);
379 		validEntityNames.put("Yscr", 0x1D4B4);
380 		validEntityNames.put("Yuml", 0x00178);
381 		validEntityNames.put("ZHcy", 0x00416);
382 		validEntityNames.put("Zacute", 0x00179);
383 		validEntityNames.put("Zcaron", 0x0017D);
384 		validEntityNames.put("Zcy", 0x00417);
385 		validEntityNames.put("Zdot", 0x0017B);
386 		validEntityNames.put("ZeroWidthSpace", 0x0200B);
387 		validEntityNames.put("Zeta", 0x00396);
388 		validEntityNames.put("Zfr", 0x02128);
389 		validEntityNames.put("Zscr", 0x1D4B5);
390 		validEntityNames.put("aacute", 0x000E1);
391 		validEntityNames.put("abreve", 0x00103);
392 		validEntityNames.put("ac", 0x0223E);
393 		validEntityNames.put("acd", 0x0223F);
394 		validEntityNames.put("acirc", 0x000E2);
395 		validEntityNames.put("acute", 0x000B4);
396 		validEntityNames.put("acy", 0x00430);
397 		validEntityNames.put("aelig", 0x000E6);
398 		validEntityNames.put("afr", 0x1D51E);
399 		validEntityNames.put("agrave", 0x000E0);
400 		validEntityNames.put("alefsym", 0x02135);
401 		validEntityNames.put("alpha", 0x003B1);
402 		validEntityNames.put("amacr", 0x00101);
403 		validEntityNames.put("amalg", 0x02A3F);
404 		validEntityNames.put("amp", 0x00026);
405 		validEntityNames.put("and", 0x02227);
406 		validEntityNames.put("andand", 0x02A55);
407 		validEntityNames.put("andd", 0x02A5C);
408 		validEntityNames.put("andslope", 0x02A58);
409 		validEntityNames.put("andv", 0x02A5A);
410 		validEntityNames.put("ang", 0x02220);
411 		validEntityNames.put("ange", 0x029A4);
412 		validEntityNames.put("angmsd", 0x02221);
413 		validEntityNames.put("angmsdaa", 0x029A8);
414 		validEntityNames.put("angmsdab", 0x029A9);
415 		validEntityNames.put("angmsdac", 0x029AA);
416 		validEntityNames.put("angmsdad", 0x029AB);
417 		validEntityNames.put("angmsdae", 0x029AC);
418 		validEntityNames.put("angmsdaf", 0x029AD);
419 		validEntityNames.put("angmsdag", 0x029AE);
420 		validEntityNames.put("angmsdah", 0x029AF);
421 		validEntityNames.put("angrt", 0x0221F);
422 		validEntityNames.put("angrtvb", 0x022BE);
423 		validEntityNames.put("angrtvbd", 0x0299D);
424 		validEntityNames.put("angsph", 0x02222);
425 		validEntityNames.put("angst", 0x0212B);
426 		validEntityNames.put("angzarr", 0x0237C);
427 		validEntityNames.put("aogon", 0x00105);
428 		validEntityNames.put("aopf", 0x1D552);
429 		validEntityNames.put("apE", 0x02A70);
430 		validEntityNames.put("apacir", 0x02A6F);
431 		validEntityNames.put("ape", 0x0224A);
432 		validEntityNames.put("apid", 0x0224B);
433 		validEntityNames.put("apos", 0x00027);
434 		validEntityNames.put("aring", 0x000E5);
435 		validEntityNames.put("ascr", 0x1D4B6);
436 		validEntityNames.put("ast", 0x0002A);
437 		validEntityNames.put("asymp", 0x02248);
438 		validEntityNames.put("asympeq", 0x0224D);
439 		validEntityNames.put("atilde", 0x000E3);
440 		validEntityNames.put("auml", 0x000E4);
441 		validEntityNames.put("awconint", 0x02233);
442 		validEntityNames.put("awint", 0x02A11);
443 		validEntityNames.put("bNot", 0x02AED);
444 		validEntityNames.put("barvee", 0x022BD);
445 		validEntityNames.put("barwed", 0x02305);
446 		validEntityNames.put("bbrk", 0x023B5);
447 		validEntityNames.put("bbrktbrk", 0x023B6);
448 		validEntityNames.put("bcong", 0x0224C);
449 		validEntityNames.put("bcy", 0x00431);
450 		validEntityNames.put("becaus", 0x02235);
451 		validEntityNames.put("bemptyv", 0x029B0);
452 		validEntityNames.put("bepsi", 0x003F6);
453 		validEntityNames.put("bernou", 0x0212C);
454 		validEntityNames.put("beta", 0x003B2);
455 		validEntityNames.put("beth", 0x02136);
456 		validEntityNames.put("bfr", 0x1D51F);
457 		validEntityNames.put("blank", 0x02423);
458 		validEntityNames.put("blk12", 0x02592);
459 		validEntityNames.put("blk14", 0x02591);
460 		validEntityNames.put("blk34", 0x02593);
461 		validEntityNames.put("block", 0x02588);
462 		validEntityNames.put("bnot", 0x02310);
463 		validEntityNames.put("bopf", 0x1D553);
464 		validEntityNames.put("bottom", 0x022A5);
465 		validEntityNames.put("bowtie", 0x022C8);
466 		validEntityNames.put("boxDL", 0x02557);
467 		validEntityNames.put("boxDR", 0x02554);
468 		validEntityNames.put("boxDl", 0x02556);
469 		validEntityNames.put("boxDr", 0x02553);
470 		validEntityNames.put("boxH", 0x02550);
471 		validEntityNames.put("boxHD", 0x02566);
472 		validEntityNames.put("boxHU", 0x02569);
473 		validEntityNames.put("boxHd", 0x02564);
474 		validEntityNames.put("boxHu", 0x02567);
475 		validEntityNames.put("boxUL", 0x0255D);
476 		validEntityNames.put("boxUR", 0x0255A);
477 		validEntityNames.put("boxUl", 0x0255C);
478 		validEntityNames.put("boxUr", 0x02559);
479 		validEntityNames.put("boxV", 0x02551);
480 		validEntityNames.put("boxVH", 0x0256C);
481 		validEntityNames.put("boxVL", 0x02563);
482 		validEntityNames.put("boxVR", 0x02560);
483 		validEntityNames.put("boxVh", 0x0256B);
484 		validEntityNames.put("boxVl", 0x02562);
485 		validEntityNames.put("boxVr", 0x0255F);
486 		validEntityNames.put("boxbox", 0x029C9);
487 		validEntityNames.put("boxdL", 0x02555);
488 		validEntityNames.put("boxdR", 0x02552);
489 		validEntityNames.put("boxdl", 0x02510);
490 		validEntityNames.put("boxdr", 0x0250C);
491 		validEntityNames.put("boxh", 0x02500);
492 		validEntityNames.put("boxhD", 0x02565);
493 		validEntityNames.put("boxhU", 0x02568);
494 		validEntityNames.put("boxhd", 0x0252C);
495 		validEntityNames.put("boxhu", 0x02534);
496 		validEntityNames.put("boxuL", 0x0255B);
497 		validEntityNames.put("boxuR", 0x02558);
498 		validEntityNames.put("boxul", 0x02518);
499 		validEntityNames.put("boxur", 0x02514);
500 		validEntityNames.put("boxv", 0x02502);
501 		validEntityNames.put("boxvH", 0x0256A);
502 		validEntityNames.put("boxvL", 0x02561);
503 		validEntityNames.put("boxvR", 0x0255E);
504 		validEntityNames.put("boxvh", 0x0253C);
505 		validEntityNames.put("boxvl", 0x02524);
506 		validEntityNames.put("boxvr", 0x0251C);
507 		validEntityNames.put("bprime", 0x02035);
508 		validEntityNames.put("breve", 0x002D8);
509 		validEntityNames.put("brvbar", 0x000A6);
510 		validEntityNames.put("bscr", 0x1D4B7);
511 		validEntityNames.put("bsemi", 0x0204F);
512 		validEntityNames.put("bsim", 0x0223D);
513 		validEntityNames.put("bsime", 0x022CD);
514 		validEntityNames.put("bsol", 0x0005C);
515 		validEntityNames.put("bsolb", 0x029C5);
516 		validEntityNames.put("bull", 0x02022);
517 		validEntityNames.put("bump", 0x0224E);
518 		validEntityNames.put("bumpE", 0x02AAE);
519 		validEntityNames.put("bumpe", 0x0224F);
520 		validEntityNames.put("cacute", 0x00107);
521 		validEntityNames.put("cap", 0x02229);
522 		validEntityNames.put("capand", 0x02A44);
523 		validEntityNames.put("capbrcup", 0x02A49);
524 		validEntityNames.put("capcap", 0x02A4B);
525 		validEntityNames.put("capcup", 0x02A47);
526 		validEntityNames.put("capdot", 0x02A40);
527 		validEntityNames.put("caret", 0x02041);
528 		validEntityNames.put("caron", 0x002C7);
529 		validEntityNames.put("ccaps", 0x02A4D);
530 		validEntityNames.put("ccaron", 0x0010D);
531 		validEntityNames.put("ccedil", 0x000E7);
532 		validEntityNames.put("ccirc", 0x00109);
533 		validEntityNames.put("ccups", 0x02A4C);
534 		validEntityNames.put("ccupssm", 0x02A50);
535 		validEntityNames.put("cdot", 0x0010B);
536 		validEntityNames.put("cedil", 0x000B8);
537 		validEntityNames.put("cemptyv", 0x029B2);
538 		validEntityNames.put("cent", 0x000A2);
539 		validEntityNames.put("cfr", 0x1D520);
540 		validEntityNames.put("chcy", 0x00447);
541 		validEntityNames.put("check", 0x02713);
542 		validEntityNames.put("chi", 0x003C7);
543 		validEntityNames.put("cir", 0x025CB);
544 		validEntityNames.put("cirE", 0x029C3);
545 		validEntityNames.put("circ", 0x002C6);
546 		validEntityNames.put("cire", 0x02257);
547 		validEntityNames.put("cirfnint", 0x02A10);
548 		validEntityNames.put("cirmid", 0x02AEF);
549 		validEntityNames.put("cirscir", 0x029C2);
550 		validEntityNames.put("clubs", 0x02663);
551 		validEntityNames.put("colon", 0x0003A);
552 		validEntityNames.put("colone", 0x02254);
553 		validEntityNames.put("comma", 0x0002C);
554 		validEntityNames.put("commat", 0x00040);
555 		validEntityNames.put("comp", 0x02201);
556 		validEntityNames.put("compfn", 0x02218);
557 		validEntityNames.put("cong", 0x02245);
558 		validEntityNames.put("congdot", 0x02A6D);
559 		validEntityNames.put("conint", 0x0222E);
560 		validEntityNames.put("copf", 0x1D554);
561 		validEntityNames.put("coprod", 0x02210);
562 		validEntityNames.put("copy", 0x000A9);
563 		validEntityNames.put("copysr", 0x02117);
564 		validEntityNames.put("crarr", 0x021B5);
565 		validEntityNames.put("cross", 0x02717);
566 		validEntityNames.put("cscr", 0x1D4B8);
567 		validEntityNames.put("csub", 0x02ACF);
568 		validEntityNames.put("csube", 0x02AD1);
569 		validEntityNames.put("csup", 0x02AD0);
570 		validEntityNames.put("csupe", 0x02AD2);
571 		validEntityNames.put("ctdot", 0x022EF);
572 		validEntityNames.put("cudarrl", 0x02938);
573 		validEntityNames.put("cudarrr", 0x02935);
574 		validEntityNames.put("cuepr", 0x022DE);
575 		validEntityNames.put("cuesc", 0x022DF);
576 		validEntityNames.put("cularr", 0x021B6);
577 		validEntityNames.put("cularrp", 0x0293D);
578 		validEntityNames.put("cup", 0x0222A);
579 		validEntityNames.put("cupbrcap", 0x02A48);
580 		validEntityNames.put("cupcap", 0x02A46);
581 		validEntityNames.put("cupcup", 0x02A4A);
582 		validEntityNames.put("cupdot", 0x0228D);
583 		validEntityNames.put("cupor", 0x02A45);
584 		validEntityNames.put("curarr", 0x021B7);
585 		validEntityNames.put("curarrm", 0x0293C);
586 		validEntityNames.put("curren", 0x000A4);
587 		validEntityNames.put("cuvee", 0x022CE);
588 		validEntityNames.put("cuwed", 0x022CF);
589 		validEntityNames.put("cwconint", 0x02232);
590 		validEntityNames.put("cwint", 0x02231);
591 		validEntityNames.put("cylcty", 0x0232D);
592 		validEntityNames.put("dArr", 0x021D3);
593 		validEntityNames.put("dHar", 0x02965);
594 		validEntityNames.put("dagger", 0x02020);
595 		validEntityNames.put("daleth", 0x02138);
596 		validEntityNames.put("darr", 0x02193);
597 		validEntityNames.put("dashv", 0x022A3);
598 		validEntityNames.put("dblac", 0x002DD);
599 		validEntityNames.put("dcaron", 0x0010F);
600 		validEntityNames.put("dcy", 0x00434);
601 		validEntityNames.put("ddarr", 0x021CA);
602 		validEntityNames.put("deg", 0x000B0);
603 		validEntityNames.put("delta", 0x003B4);
604 		validEntityNames.put("demptyv", 0x029B1);
605 		validEntityNames.put("dfisht", 0x0297F);
606 		validEntityNames.put("dfr", 0x1D521);
607 		validEntityNames.put("dharl", 0x021C3);
608 		validEntityNames.put("dharr", 0x021C2);
609 		validEntityNames.put("diam", 0x022C4);
610 		validEntityNames.put("diams", 0x02666);
611 		validEntityNames.put("disin", 0x022F2);
612 		validEntityNames.put("divide", 0x000F7);
613 		validEntityNames.put("divonx", 0x022C7);
614 		validEntityNames.put("djcy", 0x00452);
615 		validEntityNames.put("dlcorn", 0x0231E);
616 		validEntityNames.put("dlcrop", 0x0230D);
617 		validEntityNames.put("dollar", 0x00024);
618 		validEntityNames.put("dopf", 0x1D555);
619 		validEntityNames.put("dot", 0x002D9);
620 		validEntityNames.put("drcorn", 0x0231F);
621 		validEntityNames.put("drcrop", 0x0230C);
622 		validEntityNames.put("dscr", 0x1D4B9);
623 		validEntityNames.put("dscy", 0x00455);
624 		validEntityNames.put("dsol", 0x029F6);
625 		validEntityNames.put("dstrok", 0x00111);
626 		validEntityNames.put("dtdot", 0x022F1);
627 		validEntityNames.put("dtri", 0x025BF);
628 		validEntityNames.put("dtrif", 0x025BE);
629 		validEntityNames.put("duarr", 0x021F5);
630 		validEntityNames.put("duhar", 0x0296F);
631 		validEntityNames.put("dwangle", 0x029A6);
632 		validEntityNames.put("dzcy", 0x0045F);
633 		validEntityNames.put("dzigrarr", 0x027FF);
634 		validEntityNames.put("eDDot", 0x02A77);
635 		validEntityNames.put("eDot", 0x02251);
636 		validEntityNames.put("eacute", 0x000E9);
637 		validEntityNames.put("easter", 0x02A6E);
638 		validEntityNames.put("ecaron", 0x0011B);
639 		validEntityNames.put("ecir", 0x02256);
640 		validEntityNames.put("ecirc", 0x000EA);
641 		validEntityNames.put("ecolon", 0x02255);
642 		validEntityNames.put("ecy", 0x0044D);
643 		validEntityNames.put("edot", 0x00117);
644 		validEntityNames.put("efDot", 0x02252);
645 		validEntityNames.put("efr", 0x1D522);
646 		validEntityNames.put("eg", 0x02A9A);
647 		validEntityNames.put("egrave", 0x000E8);
648 		validEntityNames.put("egs", 0x02A96);
649 		validEntityNames.put("egsdot", 0x02A98);
650 		validEntityNames.put("el", 0x02A99);
651 		validEntityNames.put("elinters", 0x023E7);
652 		validEntityNames.put("ell", 0x02113);
653 		validEntityNames.put("els", 0x02A95);
654 		validEntityNames.put("elsdot", 0x02A97);
655 		validEntityNames.put("emacr", 0x00113);
656 		validEntityNames.put("empty", 0x02205);
657 		validEntityNames.put("emsp", 0x02003);
658 		validEntityNames.put("emsp13", 0x02004);
659 		validEntityNames.put("emsp14", 0x02005);
660 		validEntityNames.put("eng", 0x0014B);
661 		validEntityNames.put("ensp", 0x02002);
662 		validEntityNames.put("eogon", 0x00119);
663 		validEntityNames.put("eopf", 0x1D556);
664 		validEntityNames.put("epar", 0x022D5);
665 		validEntityNames.put("eparsl", 0x029E3);
666 		validEntityNames.put("eplus", 0x02A71);
667 		validEntityNames.put("epsi", 0x003F5);
668 		validEntityNames.put("epsiv", 0x003B5);
669 		validEntityNames.put("equals", 0x0003D);
670 		validEntityNames.put("equest", 0x0225F);
671 		validEntityNames.put("equiv", 0x02261);
672 		validEntityNames.put("equivDD", 0x02A78);
673 		validEntityNames.put("eqvparsl", 0x029E5);
674 		validEntityNames.put("erDot", 0x02253);
675 		validEntityNames.put("erarr", 0x02971);
676 		validEntityNames.put("escr", 0x0212F);
677 		validEntityNames.put("esdot", 0x02250);
678 		validEntityNames.put("esim", 0x02242);
679 		validEntityNames.put("eta", 0x003B7);
680 		validEntityNames.put("eth", 0x000F0);
681 		validEntityNames.put("euml", 0x000EB);
682 		validEntityNames.put("euro", 0x020AC);
683 		validEntityNames.put("excl", 0x00021);
684 		validEntityNames.put("exist", 0x02203);
685 		validEntityNames.put("fcy", 0x00444);
686 		validEntityNames.put("female", 0x02640);
687 		validEntityNames.put("ffilig", 0x0FB03);
688 		validEntityNames.put("fflig", 0x0FB00);
689 		validEntityNames.put("ffllig", 0x0FB04);
690 		validEntityNames.put("ffr", 0x1D523);
691 		validEntityNames.put("filig", 0x0FB01);
692 		validEntityNames.put("flat", 0x0266D);
693 		validEntityNames.put("fllig", 0x0FB02);
694 		validEntityNames.put("fltns", 0x025B1);
695 		validEntityNames.put("fnof", 0x00192);
696 		validEntityNames.put("fopf", 0x1D557);
697 		validEntityNames.put("forall", 0x02200);
698 		validEntityNames.put("fork", 0x022D4);
699 		validEntityNames.put("forkv", 0x02AD9);
700 		validEntityNames.put("fpartint", 0x02A0D);
701 		validEntityNames.put("frac12", 0x000BD);
702 		validEntityNames.put("frac13", 0x02153);
703 		validEntityNames.put("frac14", 0x000BC);
704 		validEntityNames.put("frac15", 0x02155);
705 		validEntityNames.put("frac16", 0x02159);
706 		validEntityNames.put("frac18", 0x0215B);
707 		validEntityNames.put("frac23", 0x02154);
708 		validEntityNames.put("frac25", 0x02156);
709 		validEntityNames.put("frac34", 0x000BE);
710 		validEntityNames.put("frac35", 0x02157);
711 		validEntityNames.put("frac38", 0x0215C);
712 		validEntityNames.put("frac45", 0x02158);
713 		validEntityNames.put("frac56", 0x0215A);
714 		validEntityNames.put("frac58", 0x0215D);
715 		validEntityNames.put("frac78", 0x0215E);
716 		validEntityNames.put("frasl", 0x02044);
717 		validEntityNames.put("frown", 0x02322);
718 		validEntityNames.put("fscr", 0x1D4BB);
719 		validEntityNames.put("gE", 0x02267);
720 		validEntityNames.put("gEl", 0x02A8C);
721 		validEntityNames.put("gacute", 0x001F5);
722 		validEntityNames.put("gamma", 0x003B3);
723 		validEntityNames.put("gammad", 0x003DD);
724 		validEntityNames.put("gap", 0x02A86);
725 		validEntityNames.put("gbreve", 0x0011F);
726 		validEntityNames.put("gcirc", 0x0011D);
727 		validEntityNames.put("gcy", 0x00433);
728 		validEntityNames.put("gdot", 0x00121);
729 		validEntityNames.put("ge", 0x02265);
730 		validEntityNames.put("gel", 0x022DB);
731 		validEntityNames.put("ges", 0x02A7E);
732 		validEntityNames.put("gescc", 0x02AA9);
733 		validEntityNames.put("gesdot", 0x02A80);
734 		validEntityNames.put("gesdoto", 0x02A82);
735 		validEntityNames.put("gesdotol", 0x02A84);
736 		validEntityNames.put("gesles", 0x02A94);
737 		validEntityNames.put("gfr", 0x1D524);
738 		validEntityNames.put("gimel", 0x02137);
739 		validEntityNames.put("gjcy", 0x00453);
740 		validEntityNames.put("gl", 0x02277);
741 		validEntityNames.put("glE", 0x02A92);
742 		validEntityNames.put("gla", 0x02AA5);
743 		validEntityNames.put("glj", 0x02AA4);
744 		validEntityNames.put("gnE", 0x02269);
745 		validEntityNames.put("gnap", 0x02A8A);
746 		validEntityNames.put("gne", 0x02A88);
747 		validEntityNames.put("gnsim", 0x022E7);
748 		validEntityNames.put("gopf", 0x1D558);
749 		validEntityNames.put("grave", 0x00060);
750 		validEntityNames.put("gscr", 0x0210A);
751 		validEntityNames.put("gsim", 0x02273);
752 		validEntityNames.put("gsime", 0x02A8E);
753 		validEntityNames.put("gsiml", 0x02A90);
754 		validEntityNames.put("gt", 0x0003E);
755 		validEntityNames.put("gtcc", 0x02AA7);
756 		validEntityNames.put("gtcir", 0x02A7A);
757 		validEntityNames.put("gtdot", 0x022D7);
758 		validEntityNames.put("gtlPar", 0x02995);
759 		validEntityNames.put("gtquest", 0x02A7C);
760 		validEntityNames.put("gtrarr", 0x02978);
761 		validEntityNames.put("hArr", 0x021D4);
762 		validEntityNames.put("hairsp", 0x0200A);
763 		validEntityNames.put("hamilt", 0x0210B);
764 		validEntityNames.put("hardcy", 0x0044A);
765 		validEntityNames.put("harr", 0x02194);
766 		validEntityNames.put("harrcir", 0x02948);
767 		validEntityNames.put("harrw", 0x021AD);
768 		validEntityNames.put("hcirc", 0x00125);
769 		validEntityNames.put("hearts", 0x02665);
770 		validEntityNames.put("hellip", 0x02026);
771 		validEntityNames.put("hercon", 0x022B9);
772 		validEntityNames.put("hfr", 0x1D525);
773 		validEntityNames.put("hoarr", 0x021FF);
774 		validEntityNames.put("homtht", 0x0223B);
775 		validEntityNames.put("hopf", 0x1D559);
776 		validEntityNames.put("horbar", 0x02015);
777 		validEntityNames.put("hscr", 0x1D4BD);
778 		validEntityNames.put("hstrok", 0x00127);
779 		validEntityNames.put("hybull", 0x02043);
780 		validEntityNames.put("hyphen", 0x02010);
781 		validEntityNames.put("iacute", 0x000ED);
782 		validEntityNames.put("icirc", 0x000EE);
783 		validEntityNames.put("icy", 0x00438);
784 		validEntityNames.put("iecy", 0x00435);
785 		validEntityNames.put("iexcl", 0x000A1);
786 		validEntityNames.put("ifr", 0x1D526);
787 		validEntityNames.put("igrave", 0x000EC);
788 		validEntityNames.put("iinfin", 0x029DC);
789 		validEntityNames.put("iiota", 0x02129);
790 		validEntityNames.put("ijlig", 0x00133);
791 		validEntityNames.put("imacr", 0x0012B);
792 		validEntityNames.put("image", 0x02111);
793 		validEntityNames.put("imath", 0x00131);
794 		validEntityNames.put("imof", 0x022B7);
795 		validEntityNames.put("imped", 0x001B5);
796 		validEntityNames.put("incare", 0x02105);
797 		validEntityNames.put("infin", 0x0221E);
798 		validEntityNames.put("infintie", 0x029DD);
799 		validEntityNames.put("int", 0x0222B);
800 		validEntityNames.put("intcal", 0x022BA);
801 		validEntityNames.put("integers", 0x02124);
802 		validEntityNames.put("intlarhk", 0x02A17);
803 		validEntityNames.put("iocy", 0x00451);
804 		validEntityNames.put("iogon", 0x0012F);
805 		validEntityNames.put("iopf", 0x1D55A);
806 		validEntityNames.put("iota", 0x003B9);
807 		validEntityNames.put("iprod", 0x02A3C);
808 		validEntityNames.put("iquest", 0x000BF);
809 		validEntityNames.put("iscr", 0x1D4BE);
810 		validEntityNames.put("isin", 0x02208);
811 		validEntityNames.put("isinE", 0x022F9);
812 		validEntityNames.put("isindot", 0x022F5);
813 		validEntityNames.put("isins", 0x022F4);
814 		validEntityNames.put("isinsv", 0x022F3);
815 		validEntityNames.put("itilde", 0x00129);
816 		validEntityNames.put("iukcy", 0x00456);
817 		validEntityNames.put("iuml", 0x000EF);
818 		validEntityNames.put("jcirc", 0x00135);
819 		validEntityNames.put("jcy", 0x00439);
820 		validEntityNames.put("jfr", 0x1D527);
821 		validEntityNames.put("jmath", 0x00237);
822 		validEntityNames.put("jopf", 0x1D55B);
823 		validEntityNames.put("jscr", 0x1D4BF);
824 		validEntityNames.put("jsercy", 0x00458);
825 		validEntityNames.put("jukcy", 0x00454);
826 		validEntityNames.put("kappa", 0x003BA);
827 		validEntityNames.put("kappav", 0x003F0);
828 		validEntityNames.put("kcedil", 0x00137);
829 		validEntityNames.put("kcy", 0x0043A);
830 		validEntityNames.put("kfr", 0x1D528);
831 		validEntityNames.put("kgreen", 0x00138);
832 		validEntityNames.put("khcy", 0x00445);
833 		validEntityNames.put("kjcy", 0x0045C);
834 		validEntityNames.put("kopf", 0x1D55C);
835 		validEntityNames.put("kscr", 0x1D4C0);
836 		validEntityNames.put("lAarr", 0x021DA);
837 		validEntityNames.put("lArr", 0x021D0);
838 		validEntityNames.put("lAtail", 0x0291B);
839 		validEntityNames.put("lBarr", 0x0290E);
840 		validEntityNames.put("lE", 0x02266);
841 		validEntityNames.put("lEg", 0x02A8B);
842 		validEntityNames.put("lHar", 0x02962);
843 		validEntityNames.put("lacute", 0x0013A);
844 		validEntityNames.put("laemptyv", 0x029B4);
845 		validEntityNames.put("lambda", 0x003BB);
846 		validEntityNames.put("lang", 0x027E8);
847 		validEntityNames.put("langd", 0x02991);
848 		validEntityNames.put("lap", 0x02A85);
849 		validEntityNames.put("laquo", 0x000AB);
850 		validEntityNames.put("larr", 0x02190);
851 		validEntityNames.put("larrb", 0x021E4);
852 		validEntityNames.put("larrbfs", 0x0291F);
853 		validEntityNames.put("larrfs", 0x0291D);
854 		validEntityNames.put("larrhk", 0x021A9);
855 		validEntityNames.put("larrlp", 0x021AB);
856 		validEntityNames.put("larrpl", 0x02939);
857 		validEntityNames.put("larrsim", 0x02973);
858 		validEntityNames.put("larrtl", 0x021A2);
859 		validEntityNames.put("lat", 0x02AAB);
860 		validEntityNames.put("latail", 0x02919);
861 		validEntityNames.put("late", 0x02AAD);
862 		validEntityNames.put("lbarr", 0x0290C);
863 		validEntityNames.put("lbbrk", 0x02772);
864 		validEntityNames.put("lbrke", 0x0298B);
865 		validEntityNames.put("lbrksld", 0x0298F);
866 		validEntityNames.put("lbrkslu", 0x0298D);
867 		validEntityNames.put("lcaron", 0x0013E);
868 		validEntityNames.put("lcedil", 0x0013C);
869 		validEntityNames.put("lceil", 0x02308);
870 		validEntityNames.put("lcub", 0x0007B);
871 		validEntityNames.put("lcy", 0x0043B);
872 		validEntityNames.put("ldca", 0x02936);
873 		validEntityNames.put("ldquo", 0x0201C);
874 		validEntityNames.put("ldquor", 0x0201E);
875 		validEntityNames.put("ldrdhar", 0x02967);
876 		validEntityNames.put("ldrushar", 0x0294B);
877 		validEntityNames.put("ldsh", 0x021B2);
878 		validEntityNames.put("le", 0x02264);
879 		validEntityNames.put("leg", 0x022DA);
880 		validEntityNames.put("les", 0x02A7D);
881 		validEntityNames.put("lescc", 0x02AA8);
882 		validEntityNames.put("lesdot", 0x02A7F);
883 		validEntityNames.put("lesdoto", 0x02A81);
884 		validEntityNames.put("lesdotor", 0x02A83);
885 		validEntityNames.put("lesges", 0x02A93);
886 		validEntityNames.put("lfisht", 0x0297C);
887 		validEntityNames.put("lfloor", 0x0230A);
888 		validEntityNames.put("lfr", 0x1D529);
889 		validEntityNames.put("lg", 0x02276);
890 		validEntityNames.put("lgE", 0x02A91);
891 		validEntityNames.put("lhard", 0x021BD);
892 		validEntityNames.put("lharu", 0x021BC);
893 		validEntityNames.put("lharul", 0x0296A);
894 		validEntityNames.put("lhblk", 0x02584);
895 		validEntityNames.put("ljcy", 0x00459);
896 		validEntityNames.put("llarr", 0x021C7);
897 		validEntityNames.put("llhard", 0x0296B);
898 		validEntityNames.put("lltri", 0x025FA);
899 		validEntityNames.put("lmidot", 0x00140);
900 		validEntityNames.put("lmoust", 0x023B0);
901 		validEntityNames.put("lnE", 0x02268);
902 		validEntityNames.put("lnap", 0x02A89);
903 		validEntityNames.put("lne", 0x02A87);
904 		validEntityNames.put("lnsim", 0x022E6);
905 		validEntityNames.put("loang", 0x027EC);
906 		validEntityNames.put("loarr", 0x021FD);
907 		validEntityNames.put("lobrk", 0x027E6);
908 		validEntityNames.put("lopar", 0x02985);
909 		validEntityNames.put("lopf", 0x1D55D);
910 		validEntityNames.put("loplus", 0x02A2D);
911 		validEntityNames.put("lotimes", 0x02A34);
912 		validEntityNames.put("lowast", 0x02217);
913 		validEntityNames.put("lowbar", 0x0005F);
914 		validEntityNames.put("loz", 0x025CA);
915 		validEntityNames.put("lozf", 0x029EB);
916 		validEntityNames.put("lpar", 0x00028);
917 		validEntityNames.put("lparlt", 0x02993);
918 		validEntityNames.put("lrarr", 0x021C6);
919 		validEntityNames.put("lrhar", 0x021CB);
920 		validEntityNames.put("lrhard", 0x0296D);
921 		validEntityNames.put("lrm", 0x0200E);
922 		validEntityNames.put("lrtri", 0x022BF);
923 		validEntityNames.put("lsaquo", 0x02039);
924 		validEntityNames.put("lscr", 0x1D4C1);
925 		validEntityNames.put("lsh", 0x021B0);
926 		validEntityNames.put("lsim", 0x02272);
927 		validEntityNames.put("lsime", 0x02A8D);
928 		validEntityNames.put("lsimg", 0x02A8F);
929 		validEntityNames.put("lsqb", 0x0005B);
930 		validEntityNames.put("lsquo", 0x02018);
931 		validEntityNames.put("lsquor", 0x0201A);
932 		validEntityNames.put("lstrok", 0x00142);
933 		validEntityNames.put("lt", 0x0003C);
934 		validEntityNames.put("ltcc", 0x02AA6);
935 		validEntityNames.put("ltcir", 0x02A79);
936 		validEntityNames.put("ltdot", 0x022D6);
937 		validEntityNames.put("lthree", 0x022CB);
938 		validEntityNames.put("ltimes", 0x022C9);
939 		validEntityNames.put("ltlarr", 0x02976);
940 		validEntityNames.put("ltquest", 0x02A7B);
941 		validEntityNames.put("ltrPar", 0x02996);
942 		validEntityNames.put("ltri", 0x025C3);
943 		validEntityNames.put("ltrie", 0x022B4);
944 		validEntityNames.put("ltrif", 0x025C2);
945 		validEntityNames.put("lurdshar", 0x0294A);
946 		validEntityNames.put("luruhar", 0x02966);
947 		validEntityNames.put("mDDot", 0x0223A);
948 		validEntityNames.put("macr", 0x000AF);
949 		validEntityNames.put("male", 0x02642);
950 		validEntityNames.put("malt", 0x02720);
951 		validEntityNames.put("map", 0x021A6);
952 		validEntityNames.put("marker", 0x025AE);
953 		validEntityNames.put("mcomma", 0x02A29);
954 		validEntityNames.put("mcy", 0x0043C);
955 		validEntityNames.put("mdash", 0x02014);
956 		validEntityNames.put("mfr", 0x1D52A);
957 		validEntityNames.put("mho", 0x02127);
958 		validEntityNames.put("micro", 0x000B5);
959 		validEntityNames.put("mid", 0x02223);
960 		validEntityNames.put("midcir", 0x02AF0);
961 		validEntityNames.put("middot", 0x000B7);
962 		validEntityNames.put("minus", 0x02212);
963 		validEntityNames.put("minusb", 0x0229F);
964 		validEntityNames.put("minusd", 0x02238);
965 		validEntityNames.put("minusdu", 0x02A2A);
966 		validEntityNames.put("mlcp", 0x02ADB);
967 		validEntityNames.put("mnplus", 0x02213);
968 		validEntityNames.put("models", 0x022A7);
969 		validEntityNames.put("mopf", 0x1D55E);
970 		validEntityNames.put("mscr", 0x1D4C2);
971 		validEntityNames.put("mu", 0x003BC);
972 		validEntityNames.put("mumap", 0x022B8);
973 		validEntityNames.put("nVDash", 0x022AF);
974 		validEntityNames.put("nVdash", 0x022AE);
975 		validEntityNames.put("nabla", 0x02207);
976 		validEntityNames.put("nacute", 0x00144);
977 		validEntityNames.put("nap", 0x02249);
978 		validEntityNames.put("napos", 0x00149);
979 		validEntityNames.put("natur", 0x0266E);
980 		validEntityNames.put("nbsp", 0x000A0);
981 		validEntityNames.put("ncap", 0x02A43);
982 		validEntityNames.put("ncaron", 0x00148);
983 		validEntityNames.put("ncedil", 0x00146);
984 		validEntityNames.put("ncong", 0x02247);
985 		validEntityNames.put("ncup", 0x02A42);
986 		validEntityNames.put("ncy", 0x0043D);
987 		validEntityNames.put("ndash", 0x02013);
988 		validEntityNames.put("ne", 0x02260);
989 		validEntityNames.put("neArr", 0x021D7);
990 		validEntityNames.put("nearhk", 0x02924);
991 		validEntityNames.put("nearr", 0x02197);
992 		validEntityNames.put("nequiv", 0x02262);
993 		validEntityNames.put("nesear", 0x02928);
994 		validEntityNames.put("nexist", 0x02204);
995 		validEntityNames.put("nfr", 0x1D52B);
996 		validEntityNames.put("nge", 0x02271);
997 		validEntityNames.put("ngsim", 0x02275);
998 		validEntityNames.put("ngt", 0x0226F);
999 		validEntityNames.put("nhArr", 0x021CE);
1000 		validEntityNames.put("nharr", 0x021AE);
1001 		validEntityNames.put("nhpar", 0x02AF2);
1002 		validEntityNames.put("nis", 0x022FC);
1003 		validEntityNames.put("nisd", 0x022FA);
1004 		validEntityNames.put("niv", 0x0220B);
1005 		validEntityNames.put("njcy", 0x0045A);
1006 		validEntityNames.put("nlArr", 0x021CD);
1007 		validEntityNames.put("nlarr", 0x0219A);
1008 		validEntityNames.put("nldr", 0x02025);
1009 		validEntityNames.put("nle", 0x02270);
1010 		validEntityNames.put("nlsim", 0x02274);
1011 		validEntityNames.put("nlt", 0x0226E);
1012 		validEntityNames.put("nltri", 0x022EA);
1013 		validEntityNames.put("nltrie", 0x022EC);
1014 		validEntityNames.put("nmid", 0x02224);
1015 		validEntityNames.put("nopf", 0x1D55F);
1016 		validEntityNames.put("not", 0x000AC);
1017 		validEntityNames.put("notin", 0x02209);
1018 		validEntityNames.put("notinvb", 0x022F7);
1019 		validEntityNames.put("notinvc", 0x022F6);
1020 		validEntityNames.put("notni", 0x0220C);
1021 		validEntityNames.put("notnivb", 0x022FE);
1022 		validEntityNames.put("notnivc", 0x022FD);
1023 		validEntityNames.put("npar", 0x02226);
1024 		validEntityNames.put("npolint", 0x02A14);
1025 		validEntityNames.put("npr", 0x02280);
1026 		validEntityNames.put("nprcue", 0x022E0);
1027 		validEntityNames.put("nrArr", 0x021CF);
1028 		validEntityNames.put("nrarr", 0x0219B);
1029 		validEntityNames.put("nrtri", 0x022EB);
1030 		validEntityNames.put("nrtrie", 0x022ED);
1031 		validEntityNames.put("nsc", 0x02281);
1032 		validEntityNames.put("nsccue", 0x022E1);
1033 		validEntityNames.put("nscr", 0x1D4C3);
1034 		validEntityNames.put("nsim", 0x02241);
1035 		validEntityNames.put("nsime", 0x02244);
1036 		validEntityNames.put("nsqsube", 0x022E2);
1037 		validEntityNames.put("nsqsupe", 0x022E3);
1038 		validEntityNames.put("nsub", 0x02284);
1039 		validEntityNames.put("nsube", 0x02288);
1040 		validEntityNames.put("nsup", 0x02285);
1041 		validEntityNames.put("nsupe", 0x02289);
1042 		validEntityNames.put("ntgl", 0x02279);
1043 		validEntityNames.put("ntilde", 0x000F1);
1044 		validEntityNames.put("ntlg", 0x02278);
1045 		validEntityNames.put("nu", 0x003BD);
1046 		validEntityNames.put("num", 0x00023);
1047 		validEntityNames.put("numero", 0x02116);
1048 		validEntityNames.put("numsp", 0x02007);
1049 		validEntityNames.put("nvDash", 0x022AD);
1050 		validEntityNames.put("nvHarr", 0x02904);
1051 		validEntityNames.put("nvdash", 0x022AC);
1052 		validEntityNames.put("nvinfin", 0x029DE);
1053 		validEntityNames.put("nvlArr", 0x02902);
1054 		validEntityNames.put("nvrArr", 0x02903);
1055 		validEntityNames.put("nwArr", 0x021D6);
1056 		validEntityNames.put("nwarhk", 0x02923);
1057 		validEntityNames.put("nwarr", 0x02196);
1058 		validEntityNames.put("nwnear", 0x02927);
1059 		validEntityNames.put("oS", 0x024C8);
1060 		validEntityNames.put("oacute", 0x000F3);
1061 		validEntityNames.put("oast", 0x0229B);
1062 		validEntityNames.put("ocir", 0x0229A);
1063 		validEntityNames.put("ocirc", 0x000F4);
1064 		validEntityNames.put("ocy", 0x0043E);
1065 		validEntityNames.put("odash", 0x0229D);
1066 		validEntityNames.put("odblac", 0x00151);
1067 		validEntityNames.put("odiv", 0x02A38);
1068 		validEntityNames.put("odot", 0x02299);
1069 		validEntityNames.put("odsold", 0x029BC);
1070 		validEntityNames.put("oelig", 0x00153);
1071 		validEntityNames.put("ofcir", 0x029BF);
1072 		validEntityNames.put("ofr", 0x1D52C);
1073 		validEntityNames.put("ogon", 0x002DB);
1074 		validEntityNames.put("ograve", 0x000F2);
1075 		validEntityNames.put("ogt", 0x029C1);
1076 		validEntityNames.put("ohbar", 0x029B5);
1077 		validEntityNames.put("ohm", 0x02126);
1078 		validEntityNames.put("olarr", 0x021BA);
1079 		validEntityNames.put("olcir", 0x029BE);
1080 		validEntityNames.put("olcross", 0x029BB);
1081 		validEntityNames.put("oline", 0x0203E);
1082 		validEntityNames.put("olt", 0x029C0);
1083 		validEntityNames.put("omacr", 0x0014D);
1084 		validEntityNames.put("omega", 0x003C9);
1085 		validEntityNames.put("omicron", 0x003BF);
1086 		validEntityNames.put("omid", 0x029B6);
1087 		validEntityNames.put("ominus", 0x02296);
1088 		validEntityNames.put("oopf", 0x1D560);
1089 		validEntityNames.put("opar", 0x029B7);
1090 		validEntityNames.put("operp", 0x029B9);
1091 		validEntityNames.put("oplus", 0x02295);
1092 		validEntityNames.put("or", 0x02228);
1093 		validEntityNames.put("orarr", 0x021BB);
1094 		validEntityNames.put("ord", 0x02A5D);
1095 		validEntityNames.put("order", 0x02134);
1096 		validEntityNames.put("ordf", 0x000AA);
1097 		validEntityNames.put("ordm", 0x000BA);
1098 		validEntityNames.put("origof", 0x022B6);
1099 		validEntityNames.put("oror", 0x02A56);
1100 		validEntityNames.put("orslope", 0x02A57);
1101 		validEntityNames.put("orv", 0x02A5B);
1102 		validEntityNames.put("oslash", 0x000F8);
1103 		validEntityNames.put("osol", 0x02298);
1104 		validEntityNames.put("otilde", 0x000F5);
1105 		validEntityNames.put("otimes", 0x02297);
1106 		validEntityNames.put("otimesas", 0x02A36);
1107 		validEntityNames.put("ouml", 0x000F6);
1108 		validEntityNames.put("ovbar", 0x0233D);
1109 		validEntityNames.put("par", 0x02225);
1110 		validEntityNames.put("para", 0x000B6);
1111 		validEntityNames.put("parsim", 0x02AF3);
1112 		validEntityNames.put("parsl", 0x02AFD);
1113 		validEntityNames.put("part", 0x02202);
1114 		validEntityNames.put("pcy", 0x0043F);
1115 		validEntityNames.put("percnt", 0x00025);
1116 		validEntityNames.put("period", 0x0002E);
1117 		validEntityNames.put("permil", 0x02030);
1118 		validEntityNames.put("pertenk", 0x02031);
1119 		validEntityNames.put("pfr", 0x1D52D);
1120 		validEntityNames.put("phi", 0x003C6);
1121 		validEntityNames.put("phmmat", 0x02133);
1122 		validEntityNames.put("phone", 0x0260E);
1123 		validEntityNames.put("pi", 0x003C0);
1124 		validEntityNames.put("piv", 0x003D6);
1125 		validEntityNames.put("planck", 0x0210F);
1126 		validEntityNames.put("planckh", 0x0210E);
1127 		validEntityNames.put("plus", 0x0002B);
1128 		validEntityNames.put("plusacir", 0x02A23);
1129 		validEntityNames.put("plusb", 0x0229E);
1130 		validEntityNames.put("pluscir", 0x02A22);
1131 		validEntityNames.put("plusdo", 0x02214);
1132 		validEntityNames.put("plusdu", 0x02A25);
1133 		validEntityNames.put("pluse", 0x02A72);
1134 		validEntityNames.put("plusmn", 0x000B1);
1135 		validEntityNames.put("plussim", 0x02A26);
1136 		validEntityNames.put("plustwo", 0x02A27);
1137 		validEntityNames.put("pointint", 0x02A15);
1138 		validEntityNames.put("popf", 0x1D561);
1139 		validEntityNames.put("pound", 0x000A3);
1140 		validEntityNames.put("pr", 0x0227A);
1141 		validEntityNames.put("prE", 0x02AB3);
1142 		validEntityNames.put("prap", 0x02AB7);
1143 		validEntityNames.put("prcue", 0x0227C);
1144 		validEntityNames.put("pre", 0x02AAF);
1145 		validEntityNames.put("prime", 0x02032);
1146 		validEntityNames.put("prnE", 0x02AB5);
1147 		validEntityNames.put("prnap", 0x02AB9);
1148 		validEntityNames.put("prnsim", 0x022E8);
1149 		validEntityNames.put("prod", 0x0220F);
1150 		validEntityNames.put("profalar", 0x0232E);
1151 		validEntityNames.put("profline", 0x02312);
1152 		validEntityNames.put("profsurf", 0x02313);
1153 		validEntityNames.put("prop", 0x0221D);
1154 		validEntityNames.put("prsim", 0x0227E);
1155 		validEntityNames.put("prurel", 0x022B0);
1156 		validEntityNames.put("pscr", 0x1D4C5);
1157 		validEntityNames.put("psi", 0x003C8);
1158 		validEntityNames.put("puncsp", 0x02008);
1159 		validEntityNames.put("qfr", 0x1D52E);
1160 		validEntityNames.put("qint", 0x02A0C);
1161 		validEntityNames.put("qopf", 0x1D562);
1162 		validEntityNames.put("qprime", 0x02057);
1163 		validEntityNames.put("qscr", 0x1D4C6);
1164 		validEntityNames.put("quaternions", 0x0210D);
1165 		validEntityNames.put("quatint", 0x02A16);
1166 		validEntityNames.put("quest", 0x0003F);
1167 		validEntityNames.put("quot", 0x00022);
1168 		validEntityNames.put("rAarr", 0x021DB);
1169 		validEntityNames.put("rArr", 0x021D2);
1170 		validEntityNames.put("rAtail", 0x0291C);
1171 		validEntityNames.put("rBarr", 0x0290F);
1172 		validEntityNames.put("rHar", 0x02964);
1173 		validEntityNames.put("race", 0x029DA);
1174 		validEntityNames.put("racute", 0x00155);
1175 		validEntityNames.put("radic", 0x0221A);
1176 		validEntityNames.put("raemptyv", 0x029B3);
1177 		validEntityNames.put("rang", 0x027E9);
1178 		validEntityNames.put("rangd", 0x02992);
1179 		validEntityNames.put("range", 0x029A5);
1180 		validEntityNames.put("raquo", 0x000BB);
1181 		validEntityNames.put("rarr", 0x02192);
1182 		validEntityNames.put("rarrap", 0x02975);
1183 		validEntityNames.put("rarrb", 0x021E5);
1184 		validEntityNames.put("rarrbfs", 0x02920);
1185 		validEntityNames.put("rarrc", 0x02933);
1186 		validEntityNames.put("rarrfs", 0x0291E);
1187 		validEntityNames.put("rarrhk", 0x021AA);
1188 		validEntityNames.put("rarrlp", 0x021AC);
1189 		validEntityNames.put("rarrpl", 0x02945);
1190 		validEntityNames.put("rarrsim", 0x02974);
1191 		validEntityNames.put("rarrtl", 0x021A3);
1192 		validEntityNames.put("rarrw", 0x0219D);
1193 		validEntityNames.put("ratail", 0x0291A);
1194 		validEntityNames.put("ratio", 0x02236);
1195 		validEntityNames.put("rationals", 0x0211A);
1196 		validEntityNames.put("rbarr", 0x0290D);
1197 		validEntityNames.put("rbbrk", 0x02773);
1198 		validEntityNames.put("rbrke", 0x0298C);
1199 		validEntityNames.put("rbrksld", 0x0298E);
1200 		validEntityNames.put("rbrkslu", 0x02990);
1201 		validEntityNames.put("rcaron", 0x00159);
1202 		validEntityNames.put("rcedil", 0x00157);
1203 		validEntityNames.put("rceil", 0x02309);
1204 		validEntityNames.put("rcub", 0x0007D);
1205 		validEntityNames.put("rcy", 0x00440);
1206 		validEntityNames.put("rdca", 0x02937);
1207 		validEntityNames.put("rdldhar", 0x02969);
1208 		validEntityNames.put("rdquo", 0x0201D);
1209 		validEntityNames.put("rdsh", 0x021B3);
1210 		validEntityNames.put("real", 0x0211C);
1211 		validEntityNames.put("reals", 0x0211D);
1212 		validEntityNames.put("rect", 0x025AD);
1213 		validEntityNames.put("reg", 0x000AE);
1214 		validEntityNames.put("rfisht", 0x0297D);
1215 		validEntityNames.put("rfloor", 0x0230B);
1216 		validEntityNames.put("rfr", 0x1D52F);
1217 		validEntityNames.put("rhard", 0x021C1);
1218 		validEntityNames.put("rharu", 0x021C0);
1219 		validEntityNames.put("rharul", 0x0296C);
1220 		validEntityNames.put("rho", 0x003C1);
1221 		validEntityNames.put("rhov", 0x003F1);
1222 		validEntityNames.put("ring", 0x002DA);
1223 		validEntityNames.put("rlarr", 0x021C4);
1224 		validEntityNames.put("rlhar", 0x021CC);
1225 		validEntityNames.put("rlm", 0x0200F);
1226 		validEntityNames.put("rmoust", 0x023B1);
1227 		validEntityNames.put("rnmid", 0x02AEE);
1228 		validEntityNames.put("roang", 0x027ED);
1229 		validEntityNames.put("roarr", 0x021FE);
1230 		validEntityNames.put("robrk", 0x027E7);
1231 		validEntityNames.put("ropar", 0x02986);
1232 		validEntityNames.put("ropf", 0x1D563);
1233 		validEntityNames.put("roplus", 0x02A2E);
1234 		validEntityNames.put("rotimes", 0x02A35);
1235 		validEntityNames.put("rpar", 0x00029);
1236 		validEntityNames.put("rpargt", 0x02994);
1237 		validEntityNames.put("rppolint", 0x02A12);
1238 		validEntityNames.put("rrarr", 0x021C9);
1239 		validEntityNames.put("rsaquo", 0x0203A);
1240 		validEntityNames.put("rscr", 0x1D4C7);
1241 		validEntityNames.put("rsh", 0x021B1);
1242 		validEntityNames.put("rsqb", 0x0005D);
1243 		validEntityNames.put("rsquo", 0x02019);
1244 		validEntityNames.put("rthree", 0x022CC);
1245 		validEntityNames.put("rtimes", 0x022CA);
1246 		validEntityNames.put("rtri", 0x025B9);
1247 		validEntityNames.put("rtrie", 0x022B5);
1248 		validEntityNames.put("rtrif", 0x025B8);
1249 		validEntityNames.put("rtriltri", 0x029CE);
1250 		validEntityNames.put("ruluhar", 0x02968);
1251 		validEntityNames.put("rx", 0x0211E);
1252 		validEntityNames.put("sacute", 0x0015B);
1253 		validEntityNames.put("sc", 0x0227B);
1254 		validEntityNames.put("scE", 0x02AB4);
1255 		validEntityNames.put("scap", 0x02AB8);
1256 		validEntityNames.put("scaron", 0x00161);
1257 		validEntityNames.put("sccue", 0x0227D);
1258 		validEntityNames.put("sce", 0x02AB0);
1259 		validEntityNames.put("scedil", 0x0015F);
1260 		validEntityNames.put("scirc", 0x0015D);
1261 		validEntityNames.put("scnE", 0x02AB6);
1262 		validEntityNames.put("scnap", 0x02ABA);
1263 		validEntityNames.put("scnsim", 0x022E9);
1264 		validEntityNames.put("scpolint", 0x02A13);
1265 		validEntityNames.put("scsim", 0x0227F);
1266 		validEntityNames.put("scy", 0x00441);
1267 		validEntityNames.put("sdot", 0x022C5);
1268 		validEntityNames.put("sdotb", 0x022A1);
1269 		validEntityNames.put("sdote", 0x02A66);
1270 		validEntityNames.put("seArr", 0x021D8);
1271 		validEntityNames.put("searhk", 0x02925);
1272 		validEntityNames.put("searr", 0x02198);
1273 		validEntityNames.put("sect", 0x000A7);
1274 		validEntityNames.put("semi", 0x0003B);
1275 		validEntityNames.put("seswar", 0x02929);
1276 		validEntityNames.put("setmn", 0x02216);
1277 		validEntityNames.put("sext", 0x02736);
1278 		validEntityNames.put("sfr", 0x1D530);
1279 		validEntityNames.put("sharp", 0x0266F);
1280 		validEntityNames.put("shchcy", 0x00449);
1281 		validEntityNames.put("shcy", 0x00448);
1282 		validEntityNames.put("shy", 0x000AD);
1283 		validEntityNames.put("sigma", 0x003C3);
1284 		validEntityNames.put("sigmav", 0x003C2);
1285 		validEntityNames.put("sim", 0x0223C);
1286 		validEntityNames.put("simdot", 0x02A6A);
1287 		validEntityNames.put("sime", 0x02243);
1288 		validEntityNames.put("simg", 0x02A9E);
1289 		validEntityNames.put("simgE", 0x02AA0);
1290 		validEntityNames.put("siml", 0x02A9D);
1291 		validEntityNames.put("simlE", 0x02A9F);
1292 		validEntityNames.put("simne", 0x02246);
1293 		validEntityNames.put("simplus", 0x02A24);
1294 		validEntityNames.put("simrarr", 0x02972);
1295 		validEntityNames.put("smashp", 0x02A33);
1296 		validEntityNames.put("smeparsl", 0x029E4);
1297 		validEntityNames.put("smile", 0x02323);
1298 		validEntityNames.put("smt", 0x02AAA);
1299 		validEntityNames.put("smte", 0x02AAC);
1300 		validEntityNames.put("softcy", 0x0044C);
1301 		validEntityNames.put("sol", 0x0002F);
1302 		validEntityNames.put("solb", 0x029C4);
1303 		validEntityNames.put("solbar", 0x0233F);
1304 		validEntityNames.put("sopf", 0x1D564);
1305 		validEntityNames.put("spades", 0x02660);
1306 		validEntityNames.put("sqcap", 0x02293);
1307 		validEntityNames.put("sqcup", 0x02294);
1308 		validEntityNames.put("sqsub", 0x0228F);
1309 		validEntityNames.put("sqsube", 0x02291);
1310 		validEntityNames.put("sqsup", 0x02290);
1311 		validEntityNames.put("sqsupe", 0x02292);
1312 		validEntityNames.put("squ", 0x025A1);
1313 		validEntityNames.put("squf", 0x025AA);
1314 		validEntityNames.put("sscr", 0x1D4C8);
1315 		validEntityNames.put("sstarf", 0x022C6);
1316 		validEntityNames.put("star", 0x02606);
1317 		validEntityNames.put("starf", 0x02605);
1318 		validEntityNames.put("straightphi", 0x003D5);
1319 		validEntityNames.put("sub", 0x02282);
1320 		validEntityNames.put("subE", 0x02AC5);
1321 		validEntityNames.put("subdot", 0x02ABD);
1322 		validEntityNames.put("sube", 0x02286);
1323 		validEntityNames.put("subedot", 0x02AC3);
1324 		validEntityNames.put("submult", 0x02AC1);
1325 		validEntityNames.put("subnE", 0x02ACB);
1326 		validEntityNames.put("subne", 0x0228A);
1327 		validEntityNames.put("subplus", 0x02ABF);
1328 		validEntityNames.put("subrarr", 0x02979);
1329 		validEntityNames.put("subsim", 0x02AC7);
1330 		validEntityNames.put("subsub", 0x02AD5);
1331 		validEntityNames.put("subsup", 0x02AD3);
1332 		validEntityNames.put("sum", 0x02211);
1333 		validEntityNames.put("sung", 0x0266A);
1334 		validEntityNames.put("sup", 0x02283);
1335 		validEntityNames.put("sup1", 0x000B9);
1336 		validEntityNames.put("sup2", 0x000B2);
1337 		validEntityNames.put("sup3", 0x000B3);
1338 		validEntityNames.put("supE", 0x02AC6);
1339 		validEntityNames.put("supdot", 0x02ABE);
1340 		validEntityNames.put("supdsub", 0x02AD8);
1341 		validEntityNames.put("supe", 0x02287);
1342 		validEntityNames.put("supedot", 0x02AC4);
1343 		validEntityNames.put("suphsub", 0x02AD7);
1344 		validEntityNames.put("suplarr", 0x0297B);
1345 		validEntityNames.put("supmult", 0x02AC2);
1346 		validEntityNames.put("supnE", 0x02ACC);
1347 		validEntityNames.put("supne", 0x0228B);
1348 		validEntityNames.put("supplus", 0x02AC0);
1349 		validEntityNames.put("supsim", 0x02AC8);
1350 		validEntityNames.put("supsub", 0x02AD4);
1351 		validEntityNames.put("supsup", 0x02AD6);
1352 		validEntityNames.put("swArr", 0x021D9);
1353 		validEntityNames.put("swarhk", 0x02926);
1354 		validEntityNames.put("swarr", 0x02199);
1355 		validEntityNames.put("swnwar", 0x0292A);
1356 		validEntityNames.put("szlig", 0x000DF);
1357 		validEntityNames.put("target", 0x02316);
1358 		validEntityNames.put("tau", 0x003C4);
1359 		validEntityNames.put("tbrk", 0x023B4);
1360 		validEntityNames.put("tcaron", 0x00165);
1361 		validEntityNames.put("tcedil", 0x00163);
1362 		validEntityNames.put("tcy", 0x00442);
1363 		validEntityNames.put("tdot", 0x020DB);
1364 		validEntityNames.put("telrec", 0x02315);
1365 		validEntityNames.put("tfr", 0x1D531);
1366 		validEntityNames.put("there4", 0x02234);
1367 		validEntityNames.put("theta", 0x003B8);
1368 		validEntityNames.put("thetav", 0x003D1);
1369 		validEntityNames.put("thinsp", 0x02009);
1370 		validEntityNames.put("thorn", 0x000FE);
1371 		validEntityNames.put("tilde", 0x002DC);
1372 		validEntityNames.put("times", 0x000D7);
1373 		validEntityNames.put("timesb", 0x022A0);
1374 		validEntityNames.put("timesbar", 0x02A31);
1375 		validEntityNames.put("timesd", 0x02A30);
1376 		validEntityNames.put("tint", 0x0222D);
1377 		validEntityNames.put("top", 0x022A4);
1378 		validEntityNames.put("topbot", 0x02336);
1379 		validEntityNames.put("topcir", 0x02AF1);
1380 		validEntityNames.put("topf", 0x1D565);
1381 		validEntityNames.put("topfork", 0x02ADA);
1382 		validEntityNames.put("tprime", 0x02034);
1383 		validEntityNames.put("trade", 0x02122);
1384 		validEntityNames.put("tridot", 0x025EC);
1385 		validEntityNames.put("trie", 0x0225C);
1386 		validEntityNames.put("triminus", 0x02A3A);
1387 		validEntityNames.put("triplus", 0x02A39);
1388 		validEntityNames.put("trisb", 0x029CD);
1389 		validEntityNames.put("tritime", 0x02A3B);
1390 		validEntityNames.put("trpezium", 0x023E2);
1391 		validEntityNames.put("tscr", 0x1D4C9);
1392 		validEntityNames.put("tscy", 0x00446);
1393 		validEntityNames.put("tshcy", 0x0045B);
1394 		validEntityNames.put("tstrok", 0x00167);
1395 		validEntityNames.put("twixt", 0x0226C);
1396 		validEntityNames.put("uArr", 0x021D1);
1397 		validEntityNames.put("uHar", 0x02963);
1398 		validEntityNames.put("uacute", 0x000FA);
1399 		validEntityNames.put("uarr", 0x02191);
1400 		validEntityNames.put("ubrcy", 0x0045E);
1401 		validEntityNames.put("ubreve", 0x0016D);
1402 		validEntityNames.put("ucirc", 0x000FB);
1403 		validEntityNames.put("ucy", 0x00443);
1404 		validEntityNames.put("udarr", 0x021C5);
1405 		validEntityNames.put("udblac", 0x00171);
1406 		validEntityNames.put("udhar", 0x0296E);
1407 		validEntityNames.put("ufisht", 0x0297E);
1408 		validEntityNames.put("ufr", 0x1D532);
1409 		validEntityNames.put("ugrave", 0x000F9);
1410 		validEntityNames.put("uharl", 0x021BF);
1411 		validEntityNames.put("uharr", 0x021BE);
1412 		validEntityNames.put("uhblk", 0x02580);
1413 		validEntityNames.put("ulcorn", 0x0231C);
1414 		validEntityNames.put("ulcrop", 0x0230F);
1415 		validEntityNames.put("ultri", 0x025F8);
1416 		validEntityNames.put("umacr", 0x0016B);
1417 		validEntityNames.put("uogon", 0x00173);
1418 		validEntityNames.put("uopf", 0x1D566);
1419 		validEntityNames.put("uplus", 0x0228E);
1420 		validEntityNames.put("upsi", 0x003C5);
1421 		validEntityNames.put("urcorn", 0x0231D);
1422 		validEntityNames.put("urcrop", 0x0230E);
1423 		validEntityNames.put("uring", 0x0016F);
1424 		validEntityNames.put("urtri", 0x025F9);
1425 		validEntityNames.put("uscr", 0x1D4CA);
1426 		validEntityNames.put("utdot", 0x022F0);
1427 		validEntityNames.put("utilde", 0x00169);
1428 		validEntityNames.put("utri", 0x025B5);
1429 		validEntityNames.put("utrif", 0x025B4);
1430 		validEntityNames.put("uuarr", 0x021C8);
1431 		validEntityNames.put("uuml", 0x000FC);
1432 		validEntityNames.put("uwangle", 0x029A7);
1433 		validEntityNames.put("vArr", 0x021D5);
1434 		validEntityNames.put("vBar", 0x02AE8);
1435 		validEntityNames.put("vBarv", 0x02AE9);
1436 		validEntityNames.put("vDash", 0x022A8);
1437 		validEntityNames.put("vangrt", 0x0299C);
1438 		validEntityNames.put("varr", 0x02195);
1439 		validEntityNames.put("vcy", 0x00432);
1440 		validEntityNames.put("vdash", 0x022A2);
1441 		validEntityNames.put("veebar", 0x022BB);
1442 		validEntityNames.put("veeeq", 0x0225A);
1443 		validEntityNames.put("vellip", 0x022EE);
1444 		validEntityNames.put("verbar", 0x0007C);
1445 		validEntityNames.put("vfr", 0x1D533);
1446 		validEntityNames.put("vltri", 0x022B2);
1447 		validEntityNames.put("vopf", 0x1D567);
1448 		validEntityNames.put("vrtri", 0x022B3);
1449 		validEntityNames.put("vscr", 0x1D4CB);
1450 		validEntityNames.put("vzigzag", 0x0299A);
1451 		validEntityNames.put("wcirc", 0x00175);
1452 		validEntityNames.put("wedbar", 0x02A5F);
1453 		validEntityNames.put("wedgeq", 0x02259);
1454 		validEntityNames.put("weierp", 0x02118);
1455 		validEntityNames.put("wfr", 0x1D534);
1456 		validEntityNames.put("wopf", 0x1D568);
1457 		validEntityNames.put("wreath", 0x02240);
1458 		validEntityNames.put("wscr", 0x1D4CC);
1459 		validEntityNames.put("xcap", 0x022C2);
1460 		validEntityNames.put("xcirc", 0x025EF);
1461 		validEntityNames.put("xcup", 0x022C3);
1462 		validEntityNames.put("xdtri", 0x025BD);
1463 		validEntityNames.put("xfr", 0x1D535);
1464 		validEntityNames.put("xhArr", 0x027FA);
1465 		validEntityNames.put("xharr", 0x027F7);
1466 		validEntityNames.put("xi", 0x003BE);
1467 		validEntityNames.put("xlArr", 0x027F8);
1468 		validEntityNames.put("xlarr", 0x027F5);
1469 		validEntityNames.put("xmap", 0x027FC);
1470 		validEntityNames.put("xnis", 0x022FB);
1471 		validEntityNames.put("xodot", 0x02A00);
1472 		validEntityNames.put("xopf", 0x1D569);
1473 		validEntityNames.put("xoplus", 0x02A01);
1474 		validEntityNames.put("xotime", 0x02A02);
1475 		validEntityNames.put("xrArr", 0x027F9);
1476 		validEntityNames.put("xrarr", 0x027F6);
1477 		validEntityNames.put("xscr", 0x1D4CD);
1478 		validEntityNames.put("xsqcup", 0x02A06);
1479 		validEntityNames.put("xuplus", 0x02A04);
1480 		validEntityNames.put("xutri", 0x025B3);
1481 		validEntityNames.put("xvee", 0x022C1);
1482 		validEntityNames.put("xwedge", 0x022C0);
1483 		validEntityNames.put("yacute", 0x000FD);
1484 		validEntityNames.put("yacy", 0x0044F);
1485 		validEntityNames.put("ycirc", 0x00177);
1486 		validEntityNames.put("ycy", 0x0044B);
1487 		validEntityNames.put("yen", 0x000A5);
1488 		validEntityNames.put("yfr", 0x1D536);
1489 		validEntityNames.put("yicy", 0x00457);
1490 		validEntityNames.put("yopf", 0x1D56A);
1491 		validEntityNames.put("yscr", 0x1D4CE);
1492 		validEntityNames.put("yucy", 0x0044E);
1493 		validEntityNames.put("yuml", 0x000FF);
1494 		validEntityNames.put("zacute", 0x0017A);
1495 		validEntityNames.put("zcaron", 0x0017E);
1496 		validEntityNames.put("zcy", 0x00437);
1497 		validEntityNames.put("zdot", 0x0017C);
1498 		validEntityNames.put("zeta", 0x003B6);
1499 		validEntityNames.put("zfr", 0x1D537);
1500 		validEntityNames.put("zhcy", 0x00436);
1501 		validEntityNames.put("zigrarr", 0x021DD);
1502 		validEntityNames.put("zopf", 0x1D56B);
1503 		validEntityNames.put("zscr", 0x1D4CF);
1504 		validEntityNames.put("zwj", 0x0200D);
1505 		validEntityNames.put("zwnj", 0x0200C);
1506 		
1507 		VALID_ENTITY_NAMES = Collections.unmodifiableMap(validEntityNames);
1508 	}
1509 
1510 	private static XMLOutputFactory createOutputFactory() throws FactoryConfigurationError {
1511 		try {
1512 			// Detect if we're running with the Android lib, and force repackaged Woodstox to be used
1513 			Class.forName("ca.uhn.fhir.repackage.javax.xml.stream.XMLOutputFactory");
1514 			System.setProperty("javax.xml.stream.XMLOutputFactory", "com.ctc.wstx.stax.WstxOutputFactory");
1515 		} catch (ClassNotFoundException e) {
1516 			// ok
1517 		}
1518 
1519 		XMLOutputFactory outputFactory = newOutputFactory();
1520 
1521 		if (!ourHaveLoggedStaxImplementation) {
1522 			logStaxImplementation(outputFactory.getClass());
1523 		}
1524 
1525 		/*
1526 		 * Note that these properties are Woodstox specific and they cause a crash in environments where SJSXP is
1527 		 * being used (e.g. glassfish) so we don't set them there.
1528 		 */
1529 		try {
1530 			Class.forName("com.ctc.wstx.stax.WstxOutputFactory");
1531 			if (outputFactory instanceof WstxOutputFactory) {
1532 //				((WstxOutputFactory)outputFactory).getConfig().setAttrValueEscaperFactory(new MyEscaper());
1533 				outputFactory.setProperty(XMLOutputFactory2.P_TEXT_ESCAPER, new MyEscaper());
1534 			}
1535 		} catch (ClassNotFoundException e) {
1536 			ourLog.debug("WstxOutputFactory (Woodstox) not found on classpath");
1537 		}
1538 		return outputFactory;
1539 	}
1540 
1541 	private static XMLEventWriter createXmlFragmentWriter(Writer theWriter) throws FactoryConfigurationError, XMLStreamException {
1542 		XMLOutputFactory outputFactory = getOrCreateFragmentOutputFactory();
1543 		return outputFactory.createXMLEventWriter(theWriter);
1544 	}
1545 
1546 	public static XMLEventReader createXmlReader(Reader reader) throws FactoryConfigurationError, XMLStreamException {
1547 		throwUnitTestExceptionIfConfiguredToDoSo();
1548 
1549 		XMLInputFactory inputFactory = getOrCreateInputFactory();
1550 
1551 		// Now.. create the reader and return it
1552 		return inputFactory.createXMLEventReader(reader);
1553 	}
1554 
1555 	public static XMLStreamWriter createXmlStreamWriter(Writer theWriter) throws FactoryConfigurationError, XMLStreamException {
1556 		throwUnitTestExceptionIfConfiguredToDoSo();
1557 
1558 		XMLOutputFactory outputFactory = getOrCreateOutputFactory();
1559 		return outputFactory.createXMLStreamWriter(theWriter);
1560 	}
1561 
1562 	public static XMLEventWriter createXmlWriter(Writer theWriter) throws FactoryConfigurationError, XMLStreamException {
1563 		XMLOutputFactory outputFactory = getOrCreateOutputFactory();
1564 		return outputFactory.createXMLEventWriter(theWriter);
1565 	}
1566 
1567 	/**
1568 	 * Encode a set of StAX events into a String
1569 	 */
1570 	public static String encode(List<XMLEvent> theEvents) {
1571 		try {
1572 			StringWriter w = new StringWriter();
1573 			XMLEventWriter ew = XmlUtil.createXmlFragmentWriter(w);
1574 
1575 			for (XMLEvent next : theEvents) {
1576 				if (next.isCharacters()) {
1577 					ew.add(next);
1578 				} else {
1579 					ew.add(next);
1580 				}
1581 			}
1582 			ew.close();
1583 			return w.toString();
1584 		} catch (XMLStreamException e) {
1585 			throw new DataFormatException("Problem with the contained XML events", e);
1586 		} catch (FactoryConfigurationError e) {
1587 			throw new ConfigurationException(e);
1588 		}
1589 	}
1590 
1591 	private static XMLOutputFactory getOrCreateFragmentOutputFactory() throws FactoryConfigurationError {
1592 		XMLOutputFactory retVal = ourFragmentOutputFactory;
1593 		if (retVal == null) {
1594 			retVal = createOutputFactory();
1595 			retVal.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
1596 			ourFragmentOutputFactory = retVal;
1597 			return retVal;
1598 		}
1599 		return retVal;
1600 	}
1601 
1602 	private static XMLInputFactory getOrCreateInputFactory() throws FactoryConfigurationError {
1603 		if (ourInputFactory == null) {
1604 
1605 			try {
1606 				// Detect if we're running with the Android lib, and force repackaged Woodstox to be used
1607 				Class.forName("ca.uhn.fhir.repackage.javax.xml.stream.XMLInputFactory");
1608 				System.setProperty("javax.xml.stream.XMLInputFactory", "com.ctc.wstx.stax.WstxInputFactory");
1609 			} catch (ClassNotFoundException e) {
1610 				// ok
1611 			}
1612 
1613 			XMLInputFactory inputFactory = newInputFactory();
1614 
1615 			if (!ourHaveLoggedStaxImplementation) {
1616 				logStaxImplementation(inputFactory.getClass());
1617 			}
1618 
1619 			/*
1620 			 * These two properties disable external entity processing, which can
1621 			 * be a security vulnerability.
1622 			 *
1623 			 * See https://github.com/jamesagnew/hapi-fhir/issues/339
1624 			 * https://www.owasp.org/index.php/XML_External_Entity_%28XXE%29_Processing
1625 			 */
1626 			inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); // This disables DTDs entirely for that factory
1627 			inputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", false); // disable external entities
1628 
1629 
1630 			/*
1631 			 * In the following few lines, you can uncomment the first and comment the second to disable automatic
1632 			 * parsing of extended entities, e.g. &sect;
1633 			 *
1634 			 * Note that these properties are Woodstox specific and they cause a crash in environments where SJSXP is
1635 			 * being used (e.g. glassfish) so we don't set them there.
1636 			 */
1637 			try {
1638 				Class.forName("com.ctc.wstx.stax.WstxInputFactory");
1639 				boolean isWoodstox = inputFactory instanceof com.ctc.wstx.stax.WstxInputFactory;
1640 				if ( !isWoodstox )
1641 				{
1642 					// Check if implementation is woodstox by property since instanceof check does not work if running in JBoss
1643 					try
1644 					{
1645 						isWoodstox = inputFactory.getProperty( "org.codehaus.stax2.implVersion" ) != null;
1646 					}
1647 					catch ( Exception e )
1648 					{
1649 						// ignore
1650 					}
1651 				}
1652 				if (isWoodstox) {
1653 					// inputFactory.setProperty(WstxInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
1654 					inputFactory.setProperty(WstxInputProperties.P_UNDECLARED_ENTITY_RESOLVER, XML_RESOLVER);
1655 					try {
1656 						inputFactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTE_SIZE, "100000000");
1657 					} catch (IllegalArgumentException e) {
1658 						// ignore
1659 					}
1660 				}
1661 			} catch (ClassNotFoundException e) {
1662 				ourLog.debug("WstxOutputFactory (Woodstox) not found on classpath");
1663 			}
1664 			ourInputFactory = inputFactory;
1665 		}
1666 		return ourInputFactory;
1667 	}
1668 
1669 	private static XMLOutputFactory getOrCreateOutputFactory() throws FactoryConfigurationError {
1670 		if (ourOutputFactory == null) {
1671 			ourOutputFactory = createOutputFactory();
1672 		}
1673 		return ourOutputFactory;
1674 	}
1675 
1676 
1677 	private static void logStaxImplementation(Class<?> theClass) {
1678 		IDependencyLog logger = DependencyLogFactory.createJarLogger();
1679 		if (logger != null) {
1680 			logger.logStaxImplementation(theClass);
1681 		}
1682 		ourHaveLoggedStaxImplementation = true;
1683 	}
1684 
1685 	
1686 	static XMLInputFactory newInputFactory() throws FactoryConfigurationError {
1687 		XMLInputFactory inputFactory;
1688 		try {
1689 			inputFactory = XMLInputFactory.newInstance();
1690 			throwUnitTestExceptionIfConfiguredToDoSo();
1691 		} catch (Throwable e) {
1692 			throw new ConfigurationException("Unable to initialize StAX - XML processing is disabled", e);
1693 		}
1694 		return inputFactory;
1695 	}
1696 
1697 	static XMLOutputFactory newOutputFactory() throws FactoryConfigurationError {
1698 		XMLOutputFactory outputFactory;
1699 		try {
1700 			outputFactory = XMLOutputFactory.newInstance();
1701 			throwUnitTestExceptionIfConfiguredToDoSo();
1702 		} catch (Throwable e) {
1703 			throw new ConfigurationException("Unable to initialize StAX - XML processing is disabled", e);
1704 		}
1705 		return outputFactory;
1706 	}
1707 
1708 	/**
1709 	 * Parses an XML string into a set of StAX events
1710 	 */
1711 	public static List<XMLEvent> parse(String theValue) {
1712 		if (isBlank(theValue)) {
1713 			return Collections.emptyList();
1714 		}
1715 
1716 		String val = theValue.trim();
1717 		if (!val.startsWith("<")) {
1718 			val = XhtmlDt.DIV_OPEN_FIRST + val + "</div>";
1719 		}
1720 		boolean hasProcessingInstruction = val.startsWith("<?");
1721 		if (hasProcessingInstruction && val.endsWith("?>")) {
1722 			return null;
1723 		}
1724 
1725 
1726 		try {
1727 			ArrayList<XMLEvent> value = new ArrayList<>();
1728 			StringReader reader = new StringReader(val);
1729 			XMLEventReader er = XmlUtil.createXmlReader(reader);
1730 			boolean first = true;
1731 			while (er.hasNext()) {
1732 				XMLEvent next = er.nextEvent();
1733 				if (first) {
1734 					first = false;
1735 					continue;
1736 				}
1737 				if (er.hasNext()) {
1738 					// don't add the last event
1739 					value.add(next);
1740 				}
1741 			}
1742 			return value;
1743 
1744 		} catch (XMLStreamException e) {
1745 			throw new DataFormatException("String does not appear to be valid XML/XHTML (error is \"" + e.getMessage() + "\"): " + theValue, e);
1746 		} catch (FactoryConfigurationError e) {
1747 			throw new ConfigurationException(e);
1748 		}
1749 	}
1750 
1751 	/**
1752 	 * FOR UNIT TESTS ONLY - Throw this exception for the next operation
1753 	 */
1754 	static void setThrowExceptionForUnitTest(Throwable theException) {
1755 		ourNextException = theException;
1756 	}
1757 
1758 	private static void throwUnitTestExceptionIfConfiguredToDoSo() throws FactoryConfigurationError, XMLStreamException {
1759 		if (ourNextException != null) {
1760 			if (ourNextException instanceof FactoryConfigurationError) {
1761 				throw ((FactoryConfigurationError)ourNextException);
1762 			}
1763 			throw (XMLStreamException)ourNextException;
1764 		}
1765 	}
1766 
1767 	private static final class ExtendedEntityReplacingXmlResolver implements XMLResolver {
1768 		@Override
1769 		public Object resolveEntity(String thePublicID, String theSystemID, String theBaseURI, String theNamespace) {
1770 			if (thePublicID == null && theSystemID == null) {
1771 				if (theNamespace != null && VALID_ENTITY_NAMES.containsKey(theNamespace)) {
1772 					return new String(Character.toChars(VALID_ENTITY_NAMES.get(theNamespace)));
1773 				}
1774 			}
1775 
1776 			return null;
1777 		}
1778 	}
1779 	
1780 	public static class MyEscaper implements EscapingWriterFactory {
1781 
1782 		@Override
1783 		public Writer createEscapingWriterFor(OutputStream theOut, String theEnc) throws UnsupportedEncodingException {
1784 			return createEscapingWriterFor(new OutputStreamWriter(theOut, theEnc), theEnc);
1785 		}
1786 
1787 		@Override
1788 		public Writer createEscapingWriterFor(final Writer theW, String theEnc) {
1789 			return new Writer() {
1790 
1791 				@Override
1792 				public void close() throws IOException {
1793 					theW.close();
1794 				}
1795 
1796 				@Override
1797 				public void flush() throws IOException {
1798 					theW.flush();
1799 				}
1800 
1801 				@Override
1802 				public void write(char[] theCbuf, int theOff, int theLen) throws IOException {
1803 					boolean hasEscapable = false;
1804 					for (int i = 0; i < theLen && !hasEscapable; i++) {
1805 						char nextChar = theCbuf[i + theOff];
1806 						switch (nextChar) {
1807 						case '<':
1808 						case '>':
1809 						case '"':
1810 						case '&':
1811 							hasEscapable = true;
1812 							break;
1813 						default:
1814 							break;
1815 						}
1816 					}
1817 
1818 					if (!hasEscapable) {
1819 						theW.write(theCbuf, theOff, theLen);
1820 						return;
1821 					}
1822 
1823 					String escaped = StringEscapeUtils.escapeXml10(new String(theCbuf, theOff, theLen));
1824 					theW.write(escaped.toCharArray());
1825 				}
1826 			};
1827 		}
1828 
1829 	}
1830 
1831 }