1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using System;
6 using System.IO;
7 using System.Text;
8 using System.Linq;
9 using System.Collections.Generic;
10 using System.Xml;
11 using System.Xml.Linq;
12 using System.Xml.XmlDiff;
13 using Microsoft.Test.ModuleCore;
14 using XmlCoreTest.Common;
15 
16 namespace CoreXml.Test.XLinq
17 {
18     public class BridgeHelpers : XLinqTestCase
19     {
20         private XmlDiff _diff = null;
21         private XmlReaderSettings _rsx;
22         private XmlReaderSettings _rsxNoWs;
BridgeHelpers()23         public BridgeHelpers()
24         {
25             _diff = new XmlDiff();
26             _rsx = new XmlReaderSettings();
27             _rsx.DtdProcessing = DtdProcessing.Ignore;
28 
29             _rsxNoWs = new XmlReaderSettings();
30             _rsxNoWs.DtdProcessing = DtdProcessing.Ignore;
31             _rsxNoWs.IgnoreWhitespace = true;
32             Init();
33         }
34 
35         //BridgeHelpers constants
36         public const string TestSaveFileName = "testSave.xml";
37         public const string ST_XML = "xml";
38         public const string strBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
39         public const string strBinHex = "0123456789ABCDEF";
40         public static string pLbNormEnt1 = "se3_1.ent";
41         public static string pLbNormEnt2 = "se3_2.ent";
42         public static string pGenericXml = "Generic.xml";
43         public static string pXsltCopyStylesheet = "XsltCtest.xsl";
44         public static string pValidXDR = "XdrFile.xml";
45 
46         //Reader constants
47         public const string ST_TEST_NAME = "ISDEFAULT";
48         public const string ST_ENTTEST_NAME = "ENTITY1";
49         public const string ST_MARKUP_TEST_NAME = "CHARS2";
50         public const string ST_EMPTY_TEST_NAME = "EMPTY1";
51         public static string pJunkFileXml = "Junk.xml";
52         public static string pBase64Xml = "Base64.xml";
53         public static string pBinHexXml = "BinHex.xml";
54         public const string ST_EXPAND_ENTITIES = "xxx>xxxBxxxDxxxe1fooxxx";
55         public const string ST_EXPAND_ENTITIES2 = "xxx>xxxBxxxDxxxe1fooxxx";
56         public const string ST_ENT1_ATT_EXPAND_ENTITIES = "xxx<xxxAxxxCxxxe1fooxxx";
57         public const string ST_EXPAND_CHAR_ENTITIES = "xxx>xxxBxxxDxxx";
58         public const string ST_GEN_ENT_NAME = "e1";
59         public const string ST_ENT1_ATT_EXPAND_CHAR_ENTITIES4 = "xxx&lt;xxxAxxxCxxxe1fooxxx";
60         public const string ST_IGNORE_ENTITIES = "xxx&gt;xxx&#66;xxx&#x44;xxx&e1;xxx";
61         public static string strNamespace = "http://www.foo.com";
62         public static string strAttr = "Attr";
63         public const string ST_D1_VALUE = "d1value";
64         public const string ST_GEN_ENT_VALUE = "e1foo";
65 
66         //Writer helpers
CreateWriter()67         public XmlWriter CreateWriter()
68         {
69             XDocument doc = new XDocument();
70             return CreateWriter(doc);
71         }
72 
CreateWriter(XDocument d)73         public XmlWriter CreateWriter(XDocument d)
74         {
75             return d.CreateWriter();
76         }
77 
78         //Reader helpers
GetReader()79         public XmlReader GetReader()
80         {
81             string file = Path.Combine("TestData", "XmlReader", "API", pGenericXml);
82             Stream s = FilePathUtil.getStream(file);
83 
84             if (s == null)
85             {
86                 throw new FileNotFoundException("File Not Found: " + pGenericXml);
87             }
88 
89             using (XmlReader r = XmlReader.Create(s, _rsx))
90             {
91                 XDocument doc = XDocument.Load(r, LoadOptions.PreserveWhitespace);
92                 return doc.CreateReader();
93             }
94         }
95 
GetPGenericXmlReader()96         public XmlReader GetPGenericXmlReader()
97         {
98             string file = Path.Combine("TestData", "XmlReader", "API", pGenericXml);
99             {
100                 Stream s = FilePathUtil.getStreamDirect(file);
101 
102                 if (s == null)
103                 {
104                     throw new FileNotFoundException("File Not Found: " + pGenericXml);
105                 }
106 
107                 using (XmlReader r = XmlReader.Create(s, _rsx))
108                 {
109                     XDocument doc = XDocument.Load(r, LoadOptions.PreserveWhitespace);
110                     return doc.CreateReader();
111                 }
112             }
113         }
114 
GetReader(string strSource, bool preserveWhitespace)115         public XmlReader GetReader(string strSource, bool preserveWhitespace)
116         {
117             using (XmlReader r = XmlReader.Create(FilePathUtil.getStream(strSource), preserveWhitespace ? _rsx : _rsxNoWs))
118             {
119                 XDocument doc = XDocument.Load(r, preserveWhitespace ? LoadOptions.PreserveWhitespace : LoadOptions.None);
120                 return doc.CreateReader();
121             }
122         }
123 
GetReader(string strSource)124         public XmlReader GetReader(string strSource)
125         {
126             using (XmlReader r = XmlReader.Create(FilePathUtil.getStream(strSource), _rsx))
127             {
128                 XDocument doc = XDocument.Load(r, LoadOptions.PreserveWhitespace);
129                 return doc.CreateReader();
130             }
131         }
132 
GetReader(TextReader sr)133         public XmlReader GetReader(TextReader sr)
134         {
135             using (XmlReader r = XmlReader.Create(sr, _rsx))
136             {
137                 XDocument doc = XDocument.Load(r, LoadOptions.PreserveWhitespace);
138                 return doc.CreateReader();
139             }
140         }
141 
GetReader(XmlReader r)142         public XmlReader GetReader(XmlReader r)
143         {
144             XDocument doc = XDocument.Load(r);
145             return doc.CreateReader();
146         }
147 
GetReader(Stream stream)148         public XmlReader GetReader(Stream stream)
149         {
150             using (XmlReader r = XmlReader.Create(stream, _rsx))
151             {
152                 XDocument doc = XDocument.Load(r);
153                 return doc.CreateReader();
154             }
155         }
156 
GetReaderStr(string xml)157         public XmlReader GetReaderStr(string xml)
158         {
159             using (XmlReader r = XmlReader.Create(new StringReader(xml), _rsx))
160             {
161                 XDocument doc = XDocument.Load(r, LoadOptions.PreserveWhitespace);
162                 return doc.CreateReader();
163             }
164         }
165 
GetTestFileName()166         public static string GetTestFileName()
167         {
168             return Path.Combine("TestData", "XmlReader", "API", pGenericXml);
169         }
170 
CompareReader(XDocument doc, string expectedXml)171         public bool CompareReader(XDocument doc, string expectedXml)
172         {
173             XmlReaderSettings rs = new XmlReaderSettings();
174             rs.ConformanceLevel = ConformanceLevel.Auto;
175             rs.DtdProcessing = DtdProcessing.Ignore;
176             rs.CloseInput = true;
177             _diff.Option = XmlDiffOption.IgnoreAttributeOrder;
178 
179             using (XmlReader r1 = doc.CreateReader())
180             using (XmlReader r2 = XmlReader.Create(new StringReader(expectedXml), rs))
181             {
182                 if (!_diff.Compare(r1, r2))
183                 {
184                     TestLog.WriteLine("Mismatch : expected: " + expectedXml + "\n actual: " + doc.ToString());
185                     return false;
186                 }
187             }
188             return true;
189         }
190 
CompareReader(XmlReader r1, string expectedXml)191         public bool CompareReader(XmlReader r1, string expectedXml)
192         {
193             XmlReaderSettings rs = new XmlReaderSettings();
194             rs.ConformanceLevel = ConformanceLevel.Auto;
195             rs.CloseInput = true;
196             _diff.Option = XmlDiffOption.IgnoreAttributeOrder;
197 
198             using (XmlReader r2 = XmlReader.Create(new StringReader(expectedXml), rs))
199             {
200                 if (!_diff.Compare(r1, r2))
201                 {
202                     TestLog.WriteLine("Mismatch : expected: " + expectedXml + "\n actual: ");
203                     return false;
204                 }
205             }
206             return true;
207         }
208 
GetString(string fileName)209         public string GetString(string fileName)
210         {
211             string strRet = string.Empty;
212             Stream temp = FilePathUtil.getStream(fileName);
213             StreamReader srTemp = new StreamReader(temp);
214             strRet = srTemp.ReadToEnd();
215             srTemp.Dispose();
216             temp.Dispose();
217 
218             return strRet;
219         }
220 
CompareBaseline(XDocument doc, string baselineFile)221         public bool CompareBaseline(XDocument doc, string baselineFile)
222         {
223             XmlReaderSettings rs = new XmlReaderSettings();
224             rs.ConformanceLevel = ConformanceLevel.Auto;
225             rs.DtdProcessing = DtdProcessing.Ignore;
226             rs.CloseInput = true;
227             _diff.Option = XmlDiffOption.IgnoreAttributeOrder;
228 
229             using (XmlReader r1 = XmlReader.Create(FilePathUtil.getStream(FullPath(baselineFile)), rs))
230             using (XmlReader r2 = doc.CreateReader())
231             {
232                 if (!_diff.Compare(r1, r2))
233                 {
234                     TestLog.WriteLine("Mismatch : expected: " + this.GetString(FullPath(baselineFile)) + "\n actual: " + doc.ToString());
235                     return false;
236                 }
237             }
238             return true;
239         }
240 
FullPath(string fileName)241         public string FullPath(string fileName)
242         {
243             if (fileName == null || fileName == string.Empty)
244                 return fileName;
245             return Path.Combine("TestData", "XmlWriter2", fileName);
246         }
247 
EnsureSpace(ref byte[] buffer, int len)248         public static void EnsureSpace(ref byte[] buffer, int len)
249         {
250             if (len >= buffer.Length)
251             {
252                 int originalLen = buffer.Length;
253                 byte[] newBuffer = new byte[(int)(len * 2)];
254                 for (int i = 0; i < originalLen; newBuffer[i] = buffer[i++])
255                 {
256                     // Intentionally Empty
257                 }
258                 buffer = newBuffer;
259             }
260         }
261 
WriteToBuffer(ref byte[] destBuff, ref int len, byte srcByte)262         public static void WriteToBuffer(ref byte[] destBuff, ref int len, byte srcByte)
263         {
264             EnsureSpace(ref destBuff, len);
265             destBuff[len++] = srcByte;
266             return;
267         }
268 
WriteToBuffer(ref byte[] destBuff, ref int len, byte[] srcBuff)269         public static void WriteToBuffer(ref byte[] destBuff, ref int len, byte[] srcBuff)
270         {
271             int srcArrayLen = srcBuff.Length;
272             WriteToBuffer(ref destBuff, ref len, srcBuff, 0, (int)srcArrayLen);
273             return;
274         }
275 
WriteToBuffer(ref byte[] destBuff, ref int destStart, byte[] srcBuff, int srcStart, int count)276         public static void WriteToBuffer(ref byte[] destBuff, ref int destStart, byte[] srcBuff, int srcStart, int count)
277         {
278             EnsureSpace(ref destBuff, destStart + count - 1);
279             for (int i = srcStart; i < srcStart + count; i++)
280             {
281                 destBuff[destStart++] = srcBuff[i];
282             }
283         }
284 
WriteToBuffer(ref byte[] destBuffer, ref int destBuffLen, string strValue)285         public static void WriteToBuffer(ref byte[] destBuffer, ref int destBuffLen, string strValue)
286         {
287             for (int i = 0; i < strValue.Length; i++)
288             {
289                 WriteToBuffer(ref destBuffer, ref destBuffLen, System.BitConverter.GetBytes(strValue[i]));
290             }
291             WriteToBuffer(ref destBuffer, ref destBuffLen, System.BitConverter.GetBytes('\0'));
292         }
293 
CheckClosedState(WriteState ws)294         public void CheckClosedState(WriteState ws)
295         {
296             TestLog.Compare(ws, WriteState.Closed, "WriteState should be Closed");
297         }
298 
CheckErrorState(WriteState ws)299         public void CheckErrorState(WriteState ws)
300         {
301             TestLog.Compare(ws, WriteState.Error, "WriteState should be Error");
302         }
303 
CheckElementState(WriteState ws)304         public void CheckElementState(WriteState ws)
305         {
306             TestLog.Compare(ws, WriteState.Element, "WriteState should be Element");
307         }
308 
VerifyInvalidWrite(string methodName, int iBufferSize, int iIndex, int iCount, Type exceptionType)309         public void VerifyInvalidWrite(string methodName, int iBufferSize, int iIndex, int iCount, Type exceptionType)
310         {
311             byte[] byteBuffer = new byte[iBufferSize];
312             for (int i = 0; i < iBufferSize; i++)
313                 byteBuffer[i] = (byte)(i + '0');
314 
315             char[] charBuffer = new char[iBufferSize];
316             for (int i = 0; i < iBufferSize; i++)
317                 charBuffer[i] = (char)(i + '0');
318 
319             XDocument doc = new XDocument();
320             XmlWriter w = CreateWriter(doc);
321             w.WriteStartElement("root");
322             try
323             {
324                 switch (methodName)
325                 {
326                     case "WriteBase64":
327                         w.WriteBase64(byteBuffer, iIndex, iCount);
328                         break;
329                     case "WriteRaw":
330                         w.WriteRaw(charBuffer, iIndex, iCount);
331                         break;
332                     case "WriteBinHex":
333                         w.WriteBinHex(byteBuffer, iIndex, iCount);
334                         break;
335                     case "WriteChars":
336                         w.WriteChars(charBuffer, iIndex, iCount);
337                         break;
338                     default:
339                         TestLog.Compare(false, "Unexpected method name " + methodName);
340                         break;
341                 }
342             }
343             catch (Exception e)
344             {
345                 if (exceptionType.Equals(e.GetType()))
346                 {
347                     return;
348                 }
349                 else
350                 {
351                     TestLog.WriteLine("Did not throw exception of type {0}", exceptionType);
352                 }
353             }
354             finally
355             {
356                 w.Dispose();
357             }
358             throw new TestException(TestResult.Failed, "");
359         }
360 
StringToByteArray(string src)361         public byte[] StringToByteArray(string src)
362         {
363             byte[] base64 = new byte[src.Length * 2];
364 
365             for (int i = 0; i < src.Length; i++)
366             {
367                 byte[] temp = System.BitConverter.GetBytes(src[i]);
368                 base64[2 * i] = temp[0];
369                 base64[2 * i + 1] = temp[1];
370             }
371             return base64;
372         }
373 
VerifyNode(XmlReader r, XmlNodeType eExpNodeType, string strExpName, string strExpValue)374         public static bool VerifyNode(XmlReader r, XmlNodeType eExpNodeType, string strExpName, string strExpValue)
375         {
376             bool bPassed = true;
377 
378             if (r.NodeType != eExpNodeType)
379             {
380                 TestLog.WriteLine("NodeType doesn't match");
381                 TestLog.WriteLine("    Expected NodeType: " + eExpNodeType);
382                 TestLog.WriteLine("    Actual NodeType: " + r.NodeType);
383                 bPassed = false;
384             }
385             if (r.Name != strExpName)
386             {
387                 TestLog.WriteLine("Name doesn't match:");
388                 TestLog.WriteLine("    Expected Name: '" + strExpName + "'");
389                 TestLog.WriteLine("    Actual Name: '" + r.Name + "'");
390 
391                 bPassed = false;
392             }
393             if (r.Value != strExpValue)
394             {
395                 TestLog.WriteLine("Value doesn't match:");
396                 TestLog.WriteLine("    Expected Value: '" + strExpValue + "'");
397                 TestLog.WriteLine("    Actual Value: '" + r.Value + "'");
398 
399                 bPassed = false;
400             }
401             return bPassed;
402         }
403 
CompareNode(XmlReader r, XmlNodeType eExpNodeType, string strExpName, string strExpValue)404         public void CompareNode(XmlReader r, XmlNodeType eExpNodeType, string strExpName, string strExpValue)
405         {
406             bool bNode = VerifyNode(r, eExpNodeType, strExpName, strExpValue);
407             TestLog.Compare(bNode, "VerifyNode failed");
408         }
409 
CheckXmlException(string expectedCode, XmlException e, int expectedLine, int expectedPosition)410         public void CheckXmlException(string expectedCode, XmlException e, int expectedLine, int expectedPosition)
411         {
412             TestLog.Compare(e.LineNumber, expectedLine, "CheckXmlException:LineNumber");
413             TestLog.Compare(e.LinePosition, expectedPosition, "CheckXmlException:LinePosition");
414         }
415 
PositionOnNodeType(XmlReader r, XmlNodeType nodeType)416         public void PositionOnNodeType(XmlReader r, XmlNodeType nodeType)
417         {
418             if (nodeType == XmlNodeType.DocumentType)
419             {
420                 TestLog.Skip("There is no DocumentType");
421             }
422 
423             if (r.NodeType == nodeType)
424                 return;
425 
426             while (r.Read() && r.NodeType != nodeType)
427             {
428                 if (nodeType == XmlNodeType.ProcessingInstruction && r.NodeType == XmlNodeType.XmlDeclaration)
429                 {
430                     if (string.Compare(Name, 0, ST_XML, 0, 3) != 0)
431                         return;
432                 }
433                 if (r.NodeType == XmlNodeType.Element && nodeType == XmlNodeType.Attribute)
434                 {
435                     if (r.MoveToFirstAttribute())
436                     {
437                         return;
438                     }
439                 }
440             }
441             if (r.EOF)
442             {
443                 throw new TestException(TestResult.Failed, "Couldn't find XmlNodeType " + nodeType);
444             }
445         }
446 
PositionOnElement(XmlReader r, string strElementName)447         public void PositionOnElement(XmlReader r, string strElementName)
448         {
449             if (r.NodeType == XmlNodeType.Element && r.Name == strElementName)
450                 return;
451 
452             while (r.Read())
453             {
454                 if (r.NodeType == XmlNodeType.Element && r.Name == strElementName)
455                     break;
456             }
457             if (r.EOF)
458             {
459                 throw new TestException(TestResult.Failed, "Couldn't find element '" + strElementName + "'");
460             }
461         }
462 
CreateReader(int size)463         public XmlReader CreateReader(int size)
464         {
465             StringBuilder sb = new StringBuilder();
466             sb.Append("<root>");
467             for (int i = 0; i < size; i++)
468             {
469                 sb.Append("A");
470             }
471             sb.Append("</root>");
472             return GetReaderStr(sb.ToString());
473         }
474 
475 
476 
CreateReaderIgnoreWS(string fileName)477         public XmlReader CreateReaderIgnoreWS(string fileName)
478         {
479             XmlReaderSettings readerSettings = new XmlReaderSettings();
480             readerSettings.IgnoreWhitespace = true;
481             readerSettings.CloseInput = false;
482             Stream stream = FilePathUtil.getStream(fileName);
483             return GetReader(XmlReader.Create(stream, readerSettings));
484         }
485 
CreateReader(string fileName)486         public XmlReader CreateReader(string fileName)
487         {
488             XmlReaderSettings readerSettings = new XmlReaderSettings();
489             readerSettings.DtdProcessing = DtdProcessing.Ignore;
490             readerSettings.CloseInput = false;
491 
492             Stream stream = FilePathUtil.getStream(fileName);
493             return GetReader(XmlReader.Create(stream, readerSettings));
494         }
495 
CreateReader(TextReader sr)496         public XmlReader CreateReader(TextReader sr)
497         {
498             XmlReaderSettings readerSettings = new XmlReaderSettings();
499             readerSettings.CloseInput = true;
500             return GetReader(XmlReader.Create(sr, readerSettings));
501         }
502 
503         // return string of current mode
InitStringValue(string str)504         public string InitStringValue(string str)
505         {
506             object obj = TestInput.Properties["CommandLine/" + str];
507             if (obj == null)
508             {
509                 return string.Empty;
510             }
511             return obj.ToString();
512         }
513 
DiffTwoXmlStrings(string source, string target)514         public void DiffTwoXmlStrings(string source, string target)
515         {
516             _diff.Option = XmlDiffOption.IgnoreAttributeOrder;
517             XmlReaderSettings rs = new XmlReaderSettings();
518             rs.ConformanceLevel = ConformanceLevel.Fragment;
519 
520             XmlReader src = XmlReader.Create(new StringReader(source), rs);
521             XmlReader tgt = XmlReader.Create(new StringReader(target), rs);
522             bool retVal = _diff.Compare(src, tgt);
523             if (!retVal)
524             {
525                 TestLog.WriteLine("XmlDif failed:");
526                 TestLog.WriteLine("DIFF: {0}", _diff.ToXml());
527                 throw new TestException(TestResult.Failed, "");
528             }
529         }
530 
BoolToLTMResult(bool bResult)531         public void BoolToLTMResult(bool bResult)
532         {
533             if (!bResult)
534                 throw new TestException(TestResult.Failed, "");
535         }
536 
DeleteTestFile(string strFileName)537         public static void DeleteTestFile(string strFileName)
538         {
539         }
540 
CreateByteTestFile(string strFileName)541         public static void CreateByteTestFile(string strFileName)
542         {
543             FilePathUtil.addStream(strFileName, new MemoryStream());
544             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
545             tw.WriteLine("x");
546             tw.Flush();
547             tw.Dispose();
548         }
549 
CreateUTF8EncodedTestFile(string strFileName, Encoding encode)550         public static void CreateUTF8EncodedTestFile(string strFileName, Encoding encode)
551         {
552             FilePathUtil.addStream(strFileName, new MemoryStream());
553             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName), encode);
554 
555             tw.WriteLine("<root>");
556             tw.Write("�");
557             tw.WriteLine("</root>");
558 
559             tw.Flush();
560             tw.Dispose();
561         }
562 
CreateEncodedTestFile(string strFileName, Encoding encode)563         public static void CreateEncodedTestFile(string strFileName, Encoding encode)
564         {
565             FilePathUtil.addStream(strFileName, new MemoryStream());
566             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName), encode);
567 
568             tw.WriteLine("<root>");
569             tw.WriteLine("</root>");
570 
571             tw.Flush();
572             tw.Dispose();
573         }
574 
CreateWhitespaceHandlingTestFile(string strFileName)575         public static void CreateWhitespaceHandlingTestFile(string strFileName)
576         {
577             FilePathUtil.addStream(strFileName, new MemoryStream());
578             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
579 
580             tw.WriteLine("<!DOCTYPE dt [");
581             tw.WriteLine("<!ELEMENT WHITESPACE1 (#PCDATA)*>");
582             tw.WriteLine("<!ELEMENT WHITESPACE2 (#PCDATA)*>");
583             tw.WriteLine("<!ELEMENT WHITESPACE3 (#PCDATA)*>");
584             tw.WriteLine("]>");
585             tw.WriteLine("<doc>");
586             tw.WriteLine("<WHITESPACE1>\r\n<ELEM />\r\n</WHITESPACE1>");
587             tw.WriteLine("<WHITESPACE2> <ELEM /> </WHITESPACE2>");
588             tw.WriteLine("<WHITESPACE3>\t<ELEM />\t</WHITESPACE3>");
589             tw.WriteLine("</doc>");
590             tw.Flush();
591             tw.Dispose();
592         }
593 
CreateGenericXsltTestFile(string strFileName)594         public static void CreateGenericXsltTestFile(string strFileName)
595         {
596             CreateXSLTStyleSheetWCopyTestFile(pXsltCopyStylesheet);
597             CreateGenericTestFile(strFileName);
598         }
599 
CreateGenericTestFile(string strFileName)600         public static void CreateGenericTestFile(string strFileName)
601         {
602             FilePathUtil.addStream(strFileName, new MemoryStream());
603             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
604 
605             tw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
606             tw.WriteLine("<!-- comment1 -->");
607             tw.WriteLine("<?PI1_First processing instruction?>");
608             tw.WriteLine("<?PI1a?>");
609             tw.WriteLine("<?PI1b?>");
610             tw.WriteLine("<?PI1c?>");
611             tw.WriteLine("<!DOCTYPE root SYSTEM \"AllNodeTypes.dtd\" [");
612             tw.WriteLine("<!NOTATION gif SYSTEM \"foo.exe\">");
613             tw.WriteLine("<!ELEMENT root ANY>");
614             tw.WriteLine("<!ELEMENT elem1 ANY>");
615             tw.WriteLine("<!ELEMENT ISDEFAULT ANY>");
616             tw.WriteLine("<!ENTITY % e SYSTEM \"AllNodeTypes.ent\">");
617             tw.WriteLine("%e;");
618             tw.WriteLine("<!ENTITY e1 \"e1foo\">");
619             tw.WriteLine("<!ENTITY e2 \"&ext3; e2bar\">");
620             tw.WriteLine("<!ENTITY e3 \"&e1; e3bzee \">");
621             tw.WriteLine("<!ENTITY e4 \"&e3; e4gee\">");
622             tw.WriteLine("<!ATTLIST elem1 child1 CDATA #IMPLIED child2 CDATA \"&e2;\" child3 CDATA #REQUIRED>");
623             tw.WriteLine("<!ATTLIST root xmlns:something CDATA #FIXED \"something\" xmlns:my CDATA #FIXED \"my\" xmlns:dt CDATA #FIXED \"urn:uuid:C2F41010-65B3-11d1-A29F-00AA00C14882/\">");
624             tw.WriteLine("<!ATTLIST ISDEFAULT d1 CDATA #FIXED \"d1value\">");
625 
626             tw.WriteLine("<!ATTLIST MULTISPACES att IDREFS #IMPLIED>");
627             tw.WriteLine("<!ELEMENT CATMIXED (#PCDATA)>");
628 
629             tw.WriteLine("]>");
630             tw.WriteLine("<PLAY>");
631             tw.WriteLine("<root xmlns:something=\"something\" xmlns:my=\"my\" xmlns:dt=\"urn:uuid:C2F41010-65B3-11d1-A29F-00AA00C14882/\">");
632             tw.WriteLine("<elem1 child1=\"\" child2=\"&e2;\" child3=\"something\">");
633             tw.WriteLine("text node two &e1; text node three");
634             tw.WriteLine("</elem1>");
635             tw.WriteLine("&e2;");
636             tw.WriteLine("<![CDATA[ This section contains characters that should not be interpreted as markup. For example, characters ', \",");
637             tw.WriteLine("<, >, and & are all fine here.]]>");
638             tw.WriteLine("<elem2 att1=\"id1\" att2=\"up\" att3=\"attribute3\"> ");
639             tw.WriteLine("<a />");
640             tw.WriteLine("</elem2>");
641             tw.WriteLine("<elem2> ");
642             tw.WriteLine("elem2-text1");
643             tw.WriteLine("<a refs=\"id2\"> ");
644             tw.WriteLine("this-is-a    ");
645             tw.WriteLine("</a> ");
646             tw.WriteLine("elem2-text2");
647             tw.WriteLine("&e3;");
648             tw.WriteLine("&e4;");
649             tw.WriteLine("<!-- elem2-comment1-->");
650             tw.WriteLine("elem2-text3");
651             tw.WriteLine("<b> ");
652             tw.WriteLine("this-is-b");
653             tw.WriteLine("</b>");
654             tw.WriteLine("elem2-text4");
655             tw.WriteLine("<?elem2_PI elem2-PI?>");
656             tw.WriteLine("elem2-text5");
657             tw.WriteLine("</elem2>");
658             tw.WriteLine("<elem2 att1=\"id2\"></elem2>");
659             tw.WriteLine("</root>");
660             tw.Write("<ENTITY1 att1='xxx&lt;xxx&#65;xxx&#x43;xxx&e1;xxx'>xxx&gt;xxx&#66;xxx&#x44;xxx&e1;xxx</ENTITY1>");
661             tw.WriteLine("<ENTITY2 att1='xxx&lt;xxx&#65;xxx&#x43;xxx&e1;xxx'>xxx&gt;xxx&#66;xxx&#x44;xxx&e1;xxx</ENTITY2>");
662             tw.WriteLine("<ENTITY3 att1='xxx&lt;xxx&#65;xxx&#x43;xxx&e1;xxx'>xxx&gt;xxx&#66;xxx&#x44;xxx&e1;xxx</ENTITY3>");
663             tw.WriteLine("<ENTITY4 att1='xxx&lt;xxx&#65;xxx&#x43;xxx&e1;xxx'>xxx&gt;xxx&#66;xxx&#x44;xxx&e1;xxx</ENTITY4>");
664             tw.WriteLine("<ENTITY5>&ext3;</ENTITY5>");
665             tw.WriteLine("<ATTRIBUTE1 />");
666             tw.WriteLine("<ATTRIBUTE2 a1='a1value' />");
667             tw.WriteLine("<ATTRIBUTE3 a1='a1value' a2='a2value' a3='a3value' />");
668             tw.WriteLine("<ATTRIBUTE4 a1='' />");
669             tw.WriteLine("<ATTRIBUTE5 CRLF='x\r\nx' CR='x\rx' LF='x\nx' MS='x     x' TAB='x\tx' />");
670             tw.WriteLine("<?PI1a a\r\n\rb ?>");
671             tw.WriteLine("<!--comm\r\n\rent-->");
672             tw.WriteLine("<![CDATA[cd\r\n\rata]]>");
673             tw.WriteLine("<ENDOFLINE1>x\r\nx</ENDOFLINE1>");
674             tw.WriteLine("<ENDOFLINE2>x\rx</ENDOFLINE2>");
675             tw.WriteLine("<ENDOFLINE3>x\nx</ENDOFLINE3>");
676             tw.WriteLine("<WHITESPACE1>\r\n<ELEM />\r\n</WHITESPACE1>");
677             tw.WriteLine("<WHITESPACE2> <ELEM /> </WHITESPACE2>");
678             tw.WriteLine("<WHITESPACE3>\t<ELEM />\t</WHITESPACE3>");
679             tw.WriteLine("<SKIP1 /><AFTERSKIP1 />");
680             tw.WriteLine("<SKIP2></SKIP2><AFTERSKIP2 />");
681             tw.WriteLine("<SKIP3><ELEM1 /><ELEM2>xxx yyy</ELEM2><ELEM3 /></SKIP3><AFTERSKIP3></AFTERSKIP3>");
682             tw.WriteLine("<SKIP4><ELEM1 /><ELEM2>xxx<ELEM3 /></ELEM2></SKIP4>");
683             tw.WriteLine("<CHARS1>0123456789</CHARS1>");
684             tw.WriteLine("<CHARS2>xxx<MARKUP />yyy</CHARS2>");
685             tw.WriteLine("<CHARS_ELEM1>xxx<MARKUP />yyy</CHARS_ELEM1>");
686             tw.WriteLine("<CHARS_ELEM2><MARKUP />yyy</CHARS_ELEM2>");
687             tw.WriteLine("<CHARS_ELEM3>xxx<MARKUP /></CHARS_ELEM3>");
688             tw.WriteLine("<CHARS_CDATA1>xxx<![CDATA[yyy]]>zzz</CHARS_CDATA1>");
689             tw.WriteLine("<CHARS_CDATA2><![CDATA[yyy]]>zzz</CHARS_CDATA2>");
690             tw.WriteLine("<CHARS_CDATA3>xxx<![CDATA[yyy]]></CHARS_CDATA3>");
691             tw.WriteLine("<CHARS_PI1>xxx<?PI_CHAR1 yyy?>zzz</CHARS_PI1>");
692             tw.WriteLine("<CHARS_PI2><?PI_CHAR2?>zzz</CHARS_PI2>");
693             tw.WriteLine("<CHARS_PI3>xxx<?PI_CHAR3 yyy?></CHARS_PI3>");
694             tw.WriteLine("<CHARS_COMMENT1>xxx<!-- comment1-->zzz</CHARS_COMMENT1>");
695             tw.WriteLine("<CHARS_COMMENT2><!-- comment1-->zzz</CHARS_COMMENT2>");
696             tw.WriteLine("<CHARS_COMMENT3>xxx<!-- comment1--></CHARS_COMMENT3>");
697             tw.Flush();
698             tw.WriteLine("<ISDEFAULT />");
699             tw.WriteLine("<ISDEFAULT a1='a1value' />");
700             tw.WriteLine("<BOOLEAN1>true</BOOLEAN1>");
701             tw.WriteLine("<BOOLEAN2>false</BOOLEAN2>");
702             tw.WriteLine("<BOOLEAN3>1</BOOLEAN3>");
703             tw.WriteLine("<BOOLEAN4>tRue</BOOLEAN4>");
704             tw.WriteLine("<DATETIME>1999-02-22T11:11:11</DATETIME>");
705             tw.WriteLine("<DATE>1999-02-22</DATE>");
706             tw.WriteLine("<TIME>11:11:11</TIME>");
707             tw.WriteLine("<INTEGER>9999</INTEGER>");
708             tw.WriteLine("<FLOAT>99.99</FLOAT>");
709             tw.WriteLine("<DECIMAL>.09</DECIMAL>");
710             tw.WriteLine("<CONTENT><e1 a1='a1value' a2='a2value'><e2 a1='a1value' a2='a2value'><e3 a1='a1value' a2='a2value'>leave</e3></e2></e1></CONTENT>");
711             tw.WriteLine("<TITLE><!-- this is a comment--></TITLE>");
712             tw.WriteLine("<PGROUP>");
713             tw.WriteLine("<ACT0 xmlns:foo=\"http://www.foo.com\" foo:Attr0=\"0\" foo:Attr1=\"1111111101\" foo:Attr2=\"222222202\" foo:Attr3=\"333333303\" foo:Attr4=\"444444404\" foo:Attr5=\"555555505\" foo:Attr6=\"666666606\" foo:Attr7=\"777777707\" foo:Attr8=\"888888808\" foo:Attr9=\"999999909\" />");
714             tw.WriteLine("<ACT1 Attr0=\'0\' Attr1=\'1111111101\' Attr2=\'222222202\' Attr3=\'333333303\' Attr4=\'444444404\' Attr5=\'555555505\' Attr6=\'666666606\' Attr7=\'777777707\' Attr8=\'888888808\' Attr9=\'999999909\' />");
715             tw.WriteLine("<QUOTE1 Attr0=\"0\" Attr1=\'1111111101\' Attr2=\"222222202\" Attr3=\'333333303\' />");
716             tw.WriteLine("<PERSONA>DROMIO OF EPHESUS</PERSONA>");
717             tw.WriteLine("<QUOTE2 Attr0=\"0\" Attr1=\"1111111101\" Attr2=\'222222202\' Attr3=\'333333303\' />");
718             tw.WriteLine("<QUOTE3 Attr0=\'0\' Attr1=\"1111111101\" Attr2=\'222222202\' Attr3=\"333333303\" />");
719             tw.WriteLine("<EMPTY1 />");
720             tw.WriteLine("<EMPTY2 val=\"abc\" />");
721             tw.WriteLine("<EMPTY3></EMPTY3>");
722             tw.WriteLine("<NONEMPTY0></NONEMPTY0>");
723             tw.WriteLine("<NONEMPTY1>ABCDE</NONEMPTY1>");
724             tw.WriteLine("<NONEMPTY2 val=\"abc\">1234</NONEMPTY2>");
725             tw.WriteLine("<ACT2 Attr0=\"10\" Attr1=\"1111111011\" Attr2=\"222222012\" Attr3=\"333333013\" Attr4=\"444444014\" Attr5=\"555555015\" Attr6=\"666666016\" Attr7=\"777777017\" Attr8=\"888888018\" Attr9=\"999999019\" />");
726             tw.WriteLine("<GRPDESCR>twin brothers, and sons to Aegeon and Aemilia.</GRPDESCR>");
727             tw.WriteLine("</PGROUP>");
728             tw.WriteLine("<PGROUP>");
729             tw.Flush();
730             tw.WriteLine("<XMLLANG0 xml:lang=\"en-US\">What color &e1; is it?</XMLLANG0>");
731             tw.Write("<XMLLANG1 xml:lang=\"en-GB\">What color is it?<a><b><c>Language Test</c><PERSONA>DROMIO OF EPHESUS</PERSONA></b></a></XMLLANG1>");
732             tw.WriteLine("<NOXMLLANG />");
733             tw.WriteLine("<EMPTY_XMLLANG Attr0=\"0\" xml:lang=\"en-US\" />");
734             tw.WriteLine("<XMLLANG2 xml:lang=\"en-US\">What color is it?<TITLE><!-- this is a comment--></TITLE><XMLLANG1 xml:lang=\"en-GB\">Testing language<XMLLANG0 xml:lang=\"en-US\">What color is it?</XMLLANG0>haha </XMLLANG1>hihihi</XMLLANG2>");
735             tw.WriteLine("<DONEXMLLANG />");
736             tw.WriteLine("<XMLSPACE1 xml:space=\'default\'>&lt; &gt;</XMLSPACE1>");
737             tw.Write("<XMLSPACE2 xml:space=\'preserve\'>&lt; &gt;<a><!-- comment--><b><?PI1a?><c>Space Test</c><PERSONA>DROMIO OF SYRACUSE</PERSONA></b></a></XMLSPACE2>");
738             tw.WriteLine("<NOSPACE />");
739             tw.WriteLine("<EMPTY_XMLSPACE Attr0=\"0\" xml:space=\'default\' />");
740             tw.WriteLine("<XMLSPACE2A xml:space=\'default\'>&lt; <XMLSPACE3 xml:space=\'preserve\'>  &lt; &gt; <XMLSPACE4 xml:space=\'default\'>  &lt; &gt;  </XMLSPACE4> test </XMLSPACE3> &gt;</XMLSPACE2A>");
741             tw.WriteLine("<GRPDESCR>twin brothers, and attendants on the two Antipholuses.</GRPDESCR>");
742             tw.WriteLine("<DOCNAMESPACE>");
743             tw.WriteLine("<NAMESPACE0 xmlns:bar=\"1\"><bar:check>Namespace=1</bar:check></NAMESPACE0>");
744             tw.WriteLine("<NAMESPACE1 xmlns:bar=\"1\"><a><b><c><d><bar:check>Namespace=1</bar:check><bar:check2></bar:check2></d></c></b></a></NAMESPACE1>");
745             tw.WriteLine("<NONAMESPACE>Namespace=\"\"</NONAMESPACE>");
746             tw.WriteLine("<EMPTY_NAMESPACE bar:Attr0=\"0\" xmlns:bar=\"1\" />");
747             tw.WriteLine("<EMPTY_NAMESPACE1 Attr0=\"0\" xmlns=\"14\" />");
748             tw.WriteLine("<EMPTY_NAMESPACE2 Attr0=\"0\" xmlns=\"14\"></EMPTY_NAMESPACE2>");
749             tw.WriteLine("<NAMESPACE2 xmlns:bar=\"1\"><a><b><c xmlns:bar=\"2\"><d><bar:check>Namespace=2</bar:check></d></c></b></a></NAMESPACE2>");
750             tw.WriteLine("<NAMESPACE3 xmlns=\"1\"><a xmlns:a=\"2\" xmlns:b=\"3\" xmlns:c=\"4\"><b xmlns:d=\"5\" xmlns:e=\"6\" xmlns:f='7'><c xmlns:d=\"8\" xmlns:e=\"9\" xmlns:f=\"10\">");
751             tw.WriteLine("<d xmlns:g=\"11\" xmlns:h=\"12\"><check>Namespace=1</check><testns xmlns=\"100\"><empty100 /><check100>Namespace=100</check100></testns><check1>Namespace=1</check1><d:check8>Namespace=8</d:check8></d></c><d:check5>Namespace=5</d:check5></b></a>");
752             tw.WriteLine("<a13 a:check=\"Namespace=13\" xmlns:a=\"13\" /><check14 xmlns=\"14\">Namespace=14</check14></NAMESPACE3>");
753             tw.WriteLine("<NONAMESPACE>Namespace=\"\"</NONAMESPACE>");
754             tw.WriteLine("<NONAMESPACE1 Attr1=\"one\" xmlns=\"1000\">Namespace=\"\"</NONAMESPACE1>");
755             tw.WriteLine("</DOCNAMESPACE>");
756             tw.WriteLine("</PGROUP>");
757             tw.WriteLine("<GOTOCONTENT>some text<![CDATA[cdata info]]></GOTOCONTENT>");
758             tw.WriteLine("<SKIPCONTENT att1=\"\">  <!-- comment1--> \n <?PI_SkipContent instruction?></SKIPCONTENT>");
759             tw.WriteLine("<MIXCONTENT>  <!-- comment1-->some text<?PI_SkipContent instruction?><![CDATA[cdata info]]></MIXCONTENT>");
760             tw.WriteLine("<A att=\"123\">1<B>2<C>3<D>4<E>5<F>6<G>7<H>8<I>9<J>10");
761             tw.WriteLine("<A1 att=\"456\">11<B1>12<C1>13<D1>14<E1>15<F1>16<G1>17<H1>18<I1>19<J1>20");
762             tw.WriteLine("<A2 att=\"789\">21<B2>22<C2>23<D2>24<E2>25<F2>26<G2>27<H2>28<I2>29<J2>30");
763             tw.WriteLine("<A3 att=\"123\">31<B3>32<C3>33<D3>34<E3>35<F3>36<G3>37<H3>38<I3>39<J3>40");
764             tw.WriteLine("<A4 att=\"456\">41<B4>42<C4>43<D4>44<E4>45<F4>46<G4>47<H4>48<I4>49<J4>50");
765             tw.WriteLine("<A5 att=\"789\">51<B5>52<C5>53<D5>54<E5>55<F5>56<G5>57<H5>58<I5>59<J5>60");
766             tw.WriteLine("<A6 att=\"123\">61<B6>62<C6>63<D6>64<E6>65<F6>66<G6>67<H6>68<I6>69<J6>70");
767             tw.WriteLine("<A7 att=\"456\">71<B7>72<C7>73<D7>74<E7>75<F7>76<G7>77<H7>78<I7>79<J7>80");
768             tw.WriteLine("<A8 att=\"789\">81<B8>82<C8>83<D8>84<E8>85<F8>86<G8>87<H8>88<I8>89<J8>90");
769             tw.WriteLine("<A9 att=\"123\">91<B9>92<C9>93<D9>94<E9>95<F9>96<G9>97<H9>98<I9>99<J9>100");
770             tw.WriteLine("<A10 att=\"123\">101<B10>102<C10>103<D10>104<E10>105<F10>106<G10>107<H10>108<I10>109<J10>110");
771             tw.WriteLine("</J10>109</I10>108</H10>107</G10>106</F10>105</E10>104</D10>103</C10>102</B10>101</A10>");
772             tw.WriteLine("</J9>99</I9>98</H9>97</G9>96</F9>95</E9>94</D9>93</C9>92</B9>91</A9>");
773             tw.WriteLine("</J8>89</I8>88</H8>87</G8>86</F8>85</E8>84</D8>83</C8>82</B8>81</A8>");
774             tw.WriteLine("</J7>79</I7>78</H7>77</G7>76</F7>75</E7>74</D7>73</C7>72</B7>71</A7>");
775             tw.WriteLine("</J6>69</I6>68</H6>67</G6>66</F6>65</E6>64</D6>63</C6>62</B6>61</A6>");
776             tw.WriteLine("</J5>59</I5>58</H5>57</G5>56</F5>55</E5>54</D5>53</C5>52</B5>51</A5>");
777             tw.WriteLine("</J4>49</I4>48</H4>47</G4>46</F4>45</E4>44</D4>43</C4>42</B4>41</A4>");
778             tw.WriteLine("</J3>39</I3>38</H3>37</G3>36</F3>35</E3>34</D3>33</C3>32</B3>31</A3>");
779             tw.WriteLine("</J2>29</I2>28</H2>27</G2>26</F2>25</E2>24</D2>23</C2>22</B2>21</A2>");
780             tw.WriteLine("</J1>19</I1>18</H1>17</G1>16</F1>15</E1>14</D1>13</C1>12</B1>11</A1>");
781             tw.Write("</J>9</I>8</H>7</G>6</F>5</E>4</D>3</C>2</B>1</A>");
782             tw.WriteLine("<EMPTY4 val=\"abc\"></EMPTY4>");
783             tw.WriteLine("<COMPLEX>Text<!-- comment --><![CDATA[cdata]]></COMPLEX>");
784             tw.WriteLine("<DUMMY />");
785             tw.WriteLine("<MULTISPACES att=' \r\n \t \r\r\n  n1  \r\n \t \r\r\n  n2  \r\n \t \r\r\n ' />");
786             tw.WriteLine("<CAT>AB<![CDATA[CD]]> </CAT>");
787             tw.WriteLine("<CATMIXED>AB<![CDATA[CD]]> </CATMIXED>");
788 
789             tw.WriteLine("<VALIDXMLLANG0 xml:lang=\"a\" />");
790             tw.WriteLine("<VALIDXMLLANG1 xml:lang=\"\" />");
791             tw.WriteLine("<VALIDXMLLANG2 xml:lang=\"ab-cd-\" />");
792             tw.WriteLine("<VALIDXMLLANG3 xml:lang=\"a b-cd\" />");
793 
794             tw.Write("</PLAY>");
795             tw.Flush();
796 
797             //Create external DTD file
798             FilePathUtil.addStream("AllNodeTypes.dtd", new MemoryStream());
799             TextWriter twDTD = new StreamWriter(FilePathUtil.getStream("AllNodeTypes.dtd"));
800             twDTD.WriteLine("<!ELEMENT elem2 (#PCDATA| a | b )* >");
801             twDTD.WriteLine("<!ELEMENT a ANY>");
802             twDTD.WriteLine("<!ELEMENT b ANY>");
803             twDTD.WriteLine("<!ELEMENT c ANY>");
804             twDTD.WriteLine("<!ATTLIST elem2 ");
805             twDTD.WriteLine("att1 ID #IMPLIED");
806             twDTD.WriteLine("att2 CDATA #IMPLIED");
807             twDTD.WriteLine("att3 CDATA #IMPLIED>");
808             twDTD.WriteLine("<!ATTLIST a refs IDREFS #IMPLIED>");
809             twDTD.Flush();
810 
811             // Create Ent file
812             FilePathUtil.addStream("AllNodeTypes.ent", new MemoryStream());
813             TextWriter twENT = new StreamWriter(FilePathUtil.getStream("AllNodeTypes.ent"));
814             twENT.WriteLine("<!ELEMENT foo ANY>");
815             twENT.WriteLine("<!ENTITY % ext4 \"blah\">");
816             twENT.WriteLine("<!ENTITY ext3 \"%ext4;\">");
817             twENT.Flush();
818         }
819 
CreateInvalidDTDTestFile(string strFileName)820         public static void CreateInvalidDTDTestFile(string strFileName)
821         {
822             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
823 
824             tw.WriteLine("<?xml version=\"1.0\"?><!DOCTYPE Root [<!ELEMENT Root ANY><!ELEMENT E ANY><!ATTLIST E	A1 NOTATION (N) #IMPLIED>]>");
825             tw.WriteLine("<Root><E A1=\"N\" /></Root>");
826             tw.Flush();
827             tw.Dispose();
828         }
829 
CreateValidDTDTestFile(string strFileName)830         public static void CreateValidDTDTestFile(string strFileName)
831         {
832             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
833 
834             tw.WriteLine("<?xml version=\"1.0\"?><!DOCTYPE Root [<!ELEMENT Root ANY><!ELEMENT E ANY><!ATTLIST E	IMAGE_FORMAT (bmp|jpg|gif) #IMPLIED>]>");
835             tw.Write("<Root><E A1=\"gif\" /></Root>");
836             tw.Flush();
837             tw.Dispose();
838         }
839 
CreateWellFormedDTDTestFile(string strFileName)840         public static void CreateWellFormedDTDTestFile(string strFileName)
841         {
842             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
843 
844             tw.Write("<!DOCTYPE foo [<!ELEMENT foo (e1, e2, e3)><!ENTITY bar \"<e1> <e4 /> </e1> <e2> that </e2>\">");
845             tw.Write("<!ELEMENT e1 (e4)><!ELEMENT e2 ANY><!ELEMENT e3 ANY><!ELEMENT e4 ANY>]>");
846             tw.Write("<foo>&bar;<e3 /></foo>");
847             tw.Flush();
848             tw.Dispose();
849         }
850 
CreateNonWellFormedDTDTestFile(string strFileName)851         public static void CreateNonWellFormedDTDTestFile(string strFileName)
852         {
853             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
854 
855             tw.Write("<!DOCTYPE foo [<!ELEMENT foo (e1, e2, e3)><!ENTITY bar \"<e1> <e4 /> </e1> <e2> that </e2></e2>\">");
856             tw.Write("<!ELEMENT e1 (e4)><!ELEMENT e2 ANY><!ELEMENT e3 ANY><!ELEMENT e4 ANY>]>");
857             tw.Write("<foo>&bar;<e3 /></foo>");
858             tw.Flush();
859             tw.Dispose();
860         }
861 
CreateInvWellFormedDTDTestFile(string strFileName)862         public static void CreateInvWellFormedDTDTestFile(string strFileName)
863         {
864             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
865 
866             tw.Write("<!DOCTYPE foo [<!ELEMENT foo (e1, e2, e3)><!ENTITY bar \"<e1> this </e1> <e2> that </e2>\">");
867             tw.Write("<!ELEMENT e1 (e4)><!ELEMENT e2 ANY><!ELEMENT e3 ANY><!ELEMENT e4 ANY>]>");
868             tw.Write("<foo>&bar;<e3 /></foo>");
869             tw.Flush();
870             tw.Dispose();
871         }
872 
CreateInvalidXMLXDRTestFile(string strFileName)873         public static void CreateInvalidXMLXDRTestFile(string strFileName)
874         {
875             // Create XDR before
876             CreateXDRTestFile(pValidXDR);
877 
878             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
879 
880             tw.WriteLine("<?xml version=\"1.0\" ?><e:Root xmlns:e=\"x-schema:xdrfile.xml\">");
881             tw.WriteLine("<e:e1>Element 1</e:e1></e:Root>");
882             tw.Flush();
883             tw.Dispose();
884         }
885 
CreateXDRXMLTestFile(string strFileName)886         public static void CreateXDRXMLTestFile(string strFileName)
887         {
888             // Create XDR before
889             CreateXDRTestFile(pValidXDR);
890 
891             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
892 
893             tw.WriteLine("<bar xmlns=\"x-schema:XdrFile.xml\"> <tt /> <tt /></bar>");
894             tw.Flush();
895             tw.Dispose();
896         }
897 
CreateXDRTestFile(string strFileName)898         public static void CreateXDRTestFile(string strFileName)
899         {
900             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
901 
902             tw.WriteLine("<Schema xmlns=\"uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882\"><ElementType content=\"empty\" name=\"tt\"></ElementType>");
903             tw.WriteLine("<ElementType content=\"eltOnly\" order=\"seq\" name=\"bar\" model=\"closed\"><element type=\"tt\" /><element type=\"tt\" /></ElementType>");
904             tw.WriteLine("</Schema>");
905             tw.Flush();
906             tw.Dispose();
907         }
908 
CreateInvalidNamespaceTestFile(string strFileName)909         public static void CreateInvalidNamespaceTestFile(string strFileName)
910         {
911             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
912 
913             tw.WriteLine("<NAMESPACE0 xmlns:bar=\"1\"><bar1:check>Namespace=1</bar1:check></NAMESPACE0>");
914             tw.Flush();
915             tw.Dispose();
916         }
917 
CreateNamespaceTestFile(string strFileName)918         public static void CreateNamespaceTestFile(string strFileName)
919         {
920             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
921 
922             tw.WriteLine("<DOCNAMESPACE>");
923             tw.WriteLine("<NAMESPACE0 xmlns:bar=\"1\"><bar:check>Namespace=1</bar:check></NAMESPACE0>");
924             tw.WriteLine("<NAMESPACE1 xmlns:bar=\"1\"><a><b><c><d><bar:check>Namespace=1</bar:check></d></c></b></a></NAMESPACE1>");
925             tw.WriteLine("<NONAMESPACE>Namespace=\"\"</NONAMESPACE>");
926             tw.WriteLine("<EMPTY_NAMESPACE bar:Attr0=\"0\" xmlns:bar=\"1\" />");
927             tw.WriteLine("<EMPTY_NAMESPACE1 Attr0=\"0\" xmlns=\"14\" />");
928             tw.WriteLine("<NAMESPACE2 xmlns:bar=\"1\"><a><b><c xmlns:bar=\"2\"><d><bar:check>Namespace=2</bar:check></d></c></b></a></NAMESPACE2>");
929             tw.WriteLine("<NAMESPACE3 xmlns=\"1\"><a xmlns:a=\"2\" xmlns:b=\"3\" xmlns:c=\"4\"><b xmlns:d=\"5\" xmlns:e=\"6\" xmlns:f='7'><c xmlns:d=\"8\" xmlns:e=\"9\" xmlns:f=\"10\">");
930             tw.WriteLine("<d xmlns:g=\"11\" xmlns:h=\"12\"><check>Namespace=1</check><testns xmlns=\"100\"><check100>Namespace=100</check100></testns><check1>Namespace=1</check1><d:check8>Namespace=8</d:check8></d></c><d:check5>Namespace=5</d:check5></b></a>");
931             tw.WriteLine("<a13 a:check=\"Namespace=13\" xmlns:a=\"13\" /><check14 xmlns=\"14\">Namespace=14</check14></NAMESPACE3>");
932             tw.WriteLine("<NONAMESPACE>Namespace=\"\"</NONAMESPACE>");
933             tw.WriteLine("</DOCNAMESPACE>");
934             tw.Flush();
935             tw.Dispose();
936         }
937 
CreateXmlLangTestFile(string strFileName)938         public static void CreateXmlLangTestFile(string strFileName)
939         {
940             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
941 
942             tw.WriteLine("<PGROUP>");
943             tw.WriteLine("<PERSONA>DROMIO OF EPHESUS</PERSONA>");
944             tw.WriteLine("<PERSONA>DROMIO OF SYRACUSE</PERSONA>");
945             tw.WriteLine("<XMLLANG0 xml:lang=\"en-US\">What color is it?</XMLLANG0>");
946             tw.Write("<XMLLANG1 xml:lang=\"en-GB\">What color is it?<a><b><c>Language Test</c><PERSONA>DROMIO OF EPHESUS</PERSONA></b></a></XMLLANG1>");
947             tw.WriteLine("<NOXMLLANG />");
948             tw.WriteLine("<EMPTY_XMLLANG Attr0=\"0\" xml:lang=\"en-US\" />");
949             tw.WriteLine("<XMLLANG2 xml:lang=\"en-US\">What color is it?<TITLE><!-- this is a comment--></TITLE><XMLLANG1 xml:lang=\"en-GB\">Testing language<XMLLANG0 xml:lang=\"en-US\">What color is it?</XMLLANG0>haha </XMLLANG1>hihihi</XMLLANG2>");
950             tw.WriteLine("<DONEXMLLANG />");
951             tw.WriteLine("</PGROUP>");
952             tw.Flush();
953             tw.Dispose();
954         }
955 
CreateXmlSpaceTestFile(string strFileName)956         public static void CreateXmlSpaceTestFile(string strFileName)
957         {
958             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
959 
960             tw.WriteLine("<PGROUP>");
961             tw.WriteLine("<PERSONA>DROMIO OF EPHESUS</PERSONA>");
962             tw.WriteLine("<PERSONA>DROMIO OF SYRACUSE</PERSONA>");
963             tw.WriteLine("<XMLSPACE1 xml:space=\'default\'>&lt; &gt;</XMLSPACE1>");
964             tw.Write("<XMLSPACE2 xml:space=\'preserve\'>&lt; &gt;<a><b><c>Space Test</c><PERSONA>DROMIO OF SYRACUSE</PERSONA></b></a></XMLSPACE2>");
965             tw.WriteLine("<NOSPACE />");
966             tw.WriteLine("<EMPTY_XMLSPACE Attr0=\"0\" xml:space=\'default\' />");
967             tw.WriteLine("<XMLSPACE2A xml:space=\'default\'>&lt; <XMLSPACE3 xml:space=\'preserve\'>  &lt; &gt; <XMLSPACE4 xml:space=\'default\'>  &lt; &gt;  </XMLSPACE4> test </XMLSPACE3> &gt;</XMLSPACE2A>");
968             tw.WriteLine("<GRPDESCR>twin brothers, and attendants on the two Antipholuses.</GRPDESCR>");
969             tw.WriteLine("</PGROUP>");
970             tw.Flush();
971             tw.Dispose();
972         }
973 
CreateJunkTestFile(string strFileName)974         public static void CreateJunkTestFile(string strFileName)
975         {
976             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
977 
978             string str = new String('Z', (1 << 20) - 1);
979             tw.Write(str);
980             tw.Flush();
981             tw.Dispose();
982         }
983 
CreateBase64TestFile(string strFileName)984         public static void CreateBase64TestFile(string strFileName)
985         {
986             byte[] Wbase64 = new byte[2048];
987             int Wbase64len = 0;
988             byte[] WNumOnly = new byte[1024];
989             int WNumOnlylen = 0;
990             byte[] WTextOnly = new byte[1024];
991             int WTextOnlylen = 0;
992             int i = 0;
993 
994             for (i = 0; i < strBase64.Length; i++)
995             {
996                 WriteToBuffer(ref Wbase64, ref Wbase64len, System.BitConverter.GetBytes(strBase64[i]));
997             }
998 
999             for (i = 52; i < strBase64.Length; i++)
1000             {
1001                 WriteToBuffer(ref WNumOnly, ref WNumOnlylen, System.BitConverter.GetBytes(strBase64[i]));
1002             }
1003 
1004             for (i = 0; i < strBase64.Length - 12; i++)
1005             {
1006                 WriteToBuffer(ref WTextOnly, ref WTextOnlylen, System.BitConverter.GetBytes(strBase64[i]));
1007             }
1008 
1009             FilePathUtil.addStream(strFileName, new MemoryStream());
1010 
1011             XmlWriter w = XmlWriter.Create(FilePathUtil.getStream(strFileName));
1012             w.WriteStartDocument();
1013             w.WriteDocType("Root", null, null, "<!ENTITY e 'abc'>");
1014             w.WriteStartElement("Root");
1015             w.WriteStartElement("ElemAll");
1016             w.WriteBase64(Wbase64, 0, (int)Wbase64len);
1017             w.WriteEndElement();
1018 
1019             w.WriteStartElement("ElemEmpty");
1020             w.WriteString(String.Empty);
1021             w.WriteEndElement();
1022 
1023             w.WriteStartElement("ElemNum");
1024             w.WriteBase64(WNumOnly, 0, (int)WNumOnlylen);
1025             w.WriteEndElement();
1026 
1027             w.WriteStartElement("ElemText");
1028             w.WriteBase64(WTextOnly, 0, (int)WTextOnlylen);
1029             w.WriteEndElement();
1030 
1031             w.WriteStartElement("ElemNumText");
1032             w.WriteBase64(WTextOnly, 0, (int)WTextOnlylen);
1033             w.WriteBase64(WNumOnly, 0, (int)WNumOnlylen);
1034             w.WriteEndElement();
1035 
1036             w.WriteStartElement("ElemLong");
1037             for (i = 0; i < 10; i++)
1038                 w.WriteBase64(Wbase64, 0, (int)Wbase64len);
1039             w.WriteEndElement();
1040 
1041             w.WriteElementString("ElemErr", "a&AQID");
1042 
1043             w.WriteStartElement("ElemMixed");
1044             w.WriteRaw("D2BAa<MIX>abc</MIX>AQID");
1045             w.WriteEndElement();
1046             w.WriteEndElement();
1047             w.Flush();
1048         }
1049 
CreateBinHexTestFile(string strFileName)1050         public static void CreateBinHexTestFile(string strFileName)
1051         {
1052             byte[] Wbinhex = new byte[2000];
1053             int Wbinhexlen = 0;
1054             byte[] WNumOnly = new byte[2000];
1055             int WNumOnlylen = 0;
1056             byte[] WTextOnly = new byte[2000];
1057             int WTextOnlylen = 0;
1058             int i = 0;
1059 
1060             for (i = 0; i < strBinHex.Length; i++)
1061             {
1062                 WriteToBuffer(ref Wbinhex, ref Wbinhexlen, System.BitConverter.GetBytes(strBinHex[i]));
1063             }
1064 
1065             for (i = 0; i < 10; i++)
1066             {
1067                 WriteToBuffer(ref WNumOnly, ref WNumOnlylen, System.BitConverter.GetBytes(strBinHex[i]));
1068             }
1069 
1070             for (i = 10; i < strBinHex.Length; i++)
1071             {
1072                 WriteToBuffer(ref WTextOnly, ref WTextOnlylen, System.BitConverter.GetBytes(strBinHex[i]));
1073             }
1074             FilePathUtil.addStream(strFileName, new MemoryStream());
1075 
1076             XmlWriter w = XmlWriter.Create(FilePathUtil.getStream(strFileName));
1077             w.WriteStartElement("Root");
1078             w.WriteStartElement("ElemAll");
1079             w.WriteBinHex(Wbinhex, 0, (int)Wbinhexlen);
1080             w.WriteEndElement();
1081             w.Flush();
1082 
1083             w.WriteStartElement("ElemEmpty");
1084             w.WriteString(String.Empty);
1085             w.WriteEndElement();
1086 
1087             w.WriteStartElement("ElemNum");
1088             w.WriteBinHex(WNumOnly, 0, (int)WNumOnlylen);
1089             w.WriteEndElement();
1090 
1091             w.WriteStartElement("ElemText");
1092             w.WriteBinHex(WTextOnly, 0, (int)WTextOnlylen);
1093             w.WriteEndElement();
1094 
1095             w.WriteStartElement("ElemNumText");
1096             w.WriteBinHex(WNumOnly, 0, (int)WNumOnlylen);
1097             w.WriteBinHex(WTextOnly, 0, (int)WTextOnlylen);
1098             w.WriteEndElement();
1099 
1100             w.WriteStartElement("ElemLong");
1101             for (i = 0; i < 10; i++)
1102                 w.WriteBinHex(Wbinhex, 0, (int)Wbinhexlen);
1103             w.WriteEndElement();
1104 
1105             w.WriteElementString("ElemErr", "a&A2A3");
1106 
1107             w.WriteEndElement();
1108             w.Flush();
1109             w.Dispose();
1110         }
1111 
CreateBigElementTestFile(string strFileName)1112         public static void CreateBigElementTestFile(string strFileName)
1113         {
1114             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
1115 
1116             string str = new String('Z', (1 << 20) - 1);
1117             tw.WriteLine("<Root>");
1118             tw.Write("<");
1119             tw.Write(str);
1120             tw.WriteLine("X />");
1121             tw.Flush();
1122 
1123             tw.Write("<");
1124             tw.Write(str);
1125             tw.WriteLine("Y />");
1126             tw.WriteLine("</Root>");
1127 
1128             tw.Flush();
1129             tw.Dispose();
1130         }
CreateXSLTStyleSheetWCopyTestFile(string strFileName)1131         public static void CreateXSLTStyleSheetWCopyTestFile(string strFileName)
1132         {
1133             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
1134             tw.WriteLine("<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">");
1135             tw.WriteLine("<xsl:template match=\"/\">");
1136             tw.WriteLine("<xsl:copy-of select=\"/\" />");
1137             tw.WriteLine("</xsl:template>");
1138             tw.WriteLine("</xsl:stylesheet>");
1139             tw.Flush();
1140             tw.Dispose();
1141         }
1142 
CreateConstructorTestFile(string strFileName)1143         public static void CreateConstructorTestFile(string strFileName)
1144         {
1145             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
1146 
1147             tw.WriteLine("<?xml version=\"1.0\"?>");
1148             tw.WriteLine("<ROOT>");
1149             tw.WriteLine("<ATTRIBUTE3 a1='a1value' a2='a2value' a3='a3value' />");
1150             tw.Write("</ROOT>");
1151             tw.Flush();
1152             tw.Dispose();
1153         }
1154 
CreateLineNumberTestFile(string strFileName)1155         public static void CreateLineNumberTestFile(string strFileName)
1156         {
1157             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
1158 
1159             tw.WriteLine("<?xml version=\"1.0\" ?>");
1160             tw.WriteLine(" <!DOCTYPE DT [");
1161             tw.WriteLine("<!ELEMENT root ANY>");
1162             tw.WriteLine("<!ENTITY % ext SYSTEM \"LineNumber.ent\">%ext;");
1163             tw.WriteLine("<!ENTITY e1 'e1foo'>]>");
1164             tw.WriteLine("<ROOT>");
1165             tw.WriteLine(" <ELEMENT a0='a0&e1;v' a1='a1value' a2='a2&e1;v'><EMBEDDED /></ELEMENT>");
1166             tw.WriteLine("<![CDATA[ This section contains CDATA]]>");
1167             tw.WriteLine("<CHARENTITY>AB&#x43;CD</CHARENTITY>");
1168             tw.WriteLine("<COMMENT><!-- comment node--></COMMENT>");
1169             tw.WriteLine("<ENTITYREF>A&e1;B&ext3;C</ENTITYREF>");
1170             tw.WriteLine("<?PI1?>");
1171             tw.WriteLine("<SKIP />");
1172             tw.WriteLine("<BASE64>9F6hJU++</BASE64>");
1173             tw.WriteLine("<BINHEX>9F6C</BINHEX>");
1174             tw.WriteLine("<BOOLXSD>true</BOOLXSD>");
1175             tw.WriteLine("<BOOLXDR>true</BOOLXDR>");
1176             tw.WriteLine("<DATE>2005-02-14</DATE>");
1177             tw.WriteLine("<DATETIME>2005-02-14T14:25:44</DATETIME>");
1178             tw.WriteLine("<DECIMAL>-14.25</DECIMAL>");
1179             tw.WriteLine("<INT>-1425</INT>");
1180             tw.WriteLine("<TIME>12:05:24</TIME>");
1181             tw.WriteLine("<TIMESPAN>3.12:05:24</TIMESPAN>");
1182             tw.WriteLine(" <?PI2 abc?>");
1183             tw.WriteLine("<SIG_WHITESPACE xml:space='preserve'>  </SIG_WHITESPACE>");
1184             tw.Write("</ROOT>");
1185             tw.Flush();
1186             tw.Dispose();
1187 
1188             // Create Ent file
1189             FilePathUtil.addStream("LineNumber.ent", new MemoryStream());
1190             TextWriter twENT = new StreamWriter(FilePathUtil.getStream("LineNumber.ent"));
1191             twENT.WriteLine("<!ENTITY % ext4 \"blah\">");
1192             twENT.WriteLine("<!ENTITY ext31 \"%ext4;\">");
1193             twENT.WriteLine("<!ENTITY ext3 'zzz'>");
1194             twENT.Flush();
1195             twENT.Dispose();
1196         }
1197 
CreateLbNormalizationTestFile(string strFileName)1198         public static void CreateLbNormalizationTestFile(string strFileName)
1199         {
1200             TextWriter tw = new StreamWriter(FilePathUtil.getStream(strFileName));
1201 
1202             tw.WriteLine("<?xml version=\"1.0\" standalone=\"no\"?>");
1203             tw.WriteLine("<!DOCTYPE ROOT");
1204             tw.WriteLine("[");
1205             tw.WriteLine("<!ENTITY ge1 SYSTEM \"{0}\">", pLbNormEnt1);
1206             tw.WriteLine("<!ENTITY % pe SYSTEM \"{0}\">", pLbNormEnt2);
1207             tw.WriteLine("%pe;");
1208             tw.WriteLine("]>");
1209             tw.WriteLine("<ROOT>&ge1;&ext1;</ROOT>");
1210             tw.Flush();
1211             tw.Dispose();
1212 
1213             // Create Ent file
1214             FilePathUtil.addStream(pLbNormEnt1, new MemoryStream());
1215             TextWriter twENT = new StreamWriter(FilePathUtil.getStream(pLbNormEnt1));
1216             twENT.WriteLine("<?xml version=\"1.0\"?>");
1217             twENT.WriteLine("<E1 xml:space=\"preserve\">");
1218             twENT.WriteLine("</E1>");
1219             twENT.WriteLine();
1220             twENT.Flush();
1221             twENT.Dispose();
1222 
1223             // Create Ent file
1224             FilePathUtil.addStream(pLbNormEnt2, new MemoryStream());
1225             twENT = new StreamWriter(FilePathUtil.getStream(pLbNormEnt2));
1226             twENT.WriteLine("<!ENTITY ext1 \"<E3>");
1227             twENT.WriteLine("</E3>\">");
1228             twENT.WriteLine("");
1229             twENT.WriteLine();
1230             twENT.Flush();
1231             twENT.Dispose();
1232         }
1233 
FindNodeType(XmlReader r, XmlNodeType _nodetype)1234         public bool FindNodeType(XmlReader r, XmlNodeType _nodetype)
1235         {
1236             if (r.NodeType == _nodetype)
1237                 return false;
1238 
1239             while (r.Read())
1240             {
1241                 if (r.NodeType == XmlNodeType.EntityReference)
1242                 {
1243                     if (r.CanResolveEntity)
1244                         r.ResolveEntity();
1245                 }
1246 
1247                 if (r.NodeType == XmlNodeType.ProcessingInstruction && r.NodeType == XmlNodeType.XmlDeclaration)
1248                 {
1249                     if (String.Compare(r.Name, 0, ST_XML, 0, 3) != 0)
1250                         return true;
1251                 }
1252 
1253                 if (r.NodeType == _nodetype)
1254                 {
1255                     return true;
1256                 }
1257 
1258                 if (r.NodeType == XmlNodeType.Element && (_nodetype == XmlNodeType.Attribute))
1259                 {
1260                     if (r.MoveToFirstAttribute())
1261                     {
1262                         return true;
1263                     }
1264                 }
1265             }
1266             return false;
1267         }
1268     }
1269 
1270     // Class Signatures used for verifying names
1271     public class Signatures
1272     {
1273         private string[] _stringsExpected;
1274         public int m_index;
1275 
Signatures(string[] strs)1276         public Signatures(string[] strs)
1277         {
1278             m_index = 0;
1279             _stringsExpected = strs;
1280         }
1281 
operator Signatures(string[] strs)1282         public static implicit operator Signatures(string[] strs)
1283         {
1284             return new Signatures(strs);
1285         }
1286     }
1287 
1288     public class CustomReader : XmlReader
1289     {
1290         private XmlReader _tr = null;
1291 
CustomReader(TextReader txtReader, bool isFragment)1292         public CustomReader(TextReader txtReader, bool isFragment)
1293         {
1294             if (!isFragment)
1295                 _tr = XmlReader.Create(txtReader);
1296             else
1297             {
1298                 XmlReaderSettings settings = new XmlReaderSettings();
1299                 settings.ConformanceLevel = ConformanceLevel.Fragment;
1300                 _tr = XmlReader.Create(txtReader, settings);
1301             }
1302         }
1303 
CustomReader(string url, bool isFragment)1304         public CustomReader(string url, bool isFragment)
1305         {
1306             XmlReaderSettings settings = new XmlReaderSettings();
1307             if (!isFragment)
1308             {
1309                 _tr = XmlReader.Create(url, settings);
1310             }
1311             else
1312             {
1313                 settings.ConformanceLevel = ConformanceLevel.Fragment;
1314                 _tr = XmlReader.Create(url, settings);
1315             }
1316         }
1317 
1318         public override int Depth
1319         {
1320             get
1321             {
1322                 return _tr.Depth;
1323             }
1324         }
1325 
1326         public override string Value
1327         {
1328             get
1329             {
1330                 return _tr.Value;
1331             }
1332         }
1333 
MoveToElement()1334         public override bool MoveToElement()
1335         {
1336             return _tr.MoveToElement();
1337         }
1338 
1339         public override bool IsEmptyElement
1340         {
1341             get
1342             {
1343                 return _tr.IsEmptyElement;
1344             }
1345         }
1346 
1347         public override string LocalName
1348         {
1349             get
1350             {
1351                 return _tr.LocalName;
1352             }
1353         }
1354 
1355         public override XmlNodeType NodeType
1356         {
1357             get
1358             {
1359                 return _tr.NodeType;
1360             }
1361         }
1362 
MoveToNextAttribute()1363         public override bool MoveToNextAttribute()
1364         {
1365             return _tr.MoveToNextAttribute();
1366         }
1367 
MoveToFirstAttribute()1368         public override bool MoveToFirstAttribute()
1369         {
1370             return _tr.MoveToFirstAttribute();
1371         }
1372 
LookupNamespace(string prefix)1373         public override string LookupNamespace(string prefix)
1374         {
1375             return _tr.LookupNamespace(prefix);
1376         }
1377 
Dispose()1378         public new void Dispose()
1379         {
1380             _tr.Dispose();
1381         }
1382 
1383         public override bool EOF
1384         {
1385             get
1386             {
1387                 return _tr.EOF;
1388             }
1389         }
1390 
1391         public override bool HasValue
1392         {
1393             get
1394             {
1395                 return _tr.HasValue;
1396             }
1397         }
1398 
1399         public override string NamespaceURI
1400         {
1401             get
1402             {
1403                 return _tr.NamespaceURI;
1404             }
1405         }
1406 
Read()1407         public override bool Read()
1408         {
1409             return _tr.Read();
1410         }
1411 
1412         public override XmlNameTable NameTable
1413         {
1414             get
1415             {
1416                 return _tr.NameTable;
1417             }
1418         }
1419 
1420         public override bool CanResolveEntity
1421         {
1422             get
1423             {
1424                 return _tr.CanResolveEntity;
1425             }
1426         }
1427 
ResolveEntity()1428         public override void ResolveEntity()
1429         {
1430             _tr.ResolveEntity();
1431         }
1432 
GetAttribute(string name, string namespaceURI)1433         public override string GetAttribute(string name, string namespaceURI)
1434         {
1435             return _tr.GetAttribute(name, namespaceURI);
1436         }
1437 
GetAttribute(string name)1438         public override string GetAttribute(string name)
1439         {
1440             return _tr.GetAttribute(name);
1441         }
1442 
GetAttribute(int i)1443         public override string GetAttribute(int i)
1444         {
1445             return _tr.GetAttribute(i);
1446         }
1447 
1448         public override string BaseURI
1449         {
1450             get
1451             {
1452                 return _tr.BaseURI;
1453             }
1454         }
1455 
ReadAttributeValue()1456         public override bool ReadAttributeValue()
1457         {
1458             return _tr.ReadAttributeValue();
1459         }
1460 
1461         public override string Prefix
1462         {
1463             get
1464             {
1465                 return _tr.Prefix;
1466             }
1467         }
1468 
MoveToAttribute(string name, string ns)1469         public override bool MoveToAttribute(string name, string ns)
1470         {
1471             return _tr.MoveToAttribute(name, ns);
1472         }
1473 
MoveToAttribute(string name)1474         public override bool MoveToAttribute(string name)
1475         {
1476             return _tr.MoveToAttribute(name);
1477         }
1478 
1479         public override int AttributeCount
1480         {
1481             get
1482             {
1483                 return _tr.AttributeCount;
1484             }
1485         }
1486 
1487         public override ReadState ReadState
1488         {
1489             get
1490             {
1491                 return _tr.ReadState;
1492             }
1493         }
1494     }
1495 
1496     public class CustomWriter : XmlWriter
1497     {
1498         private XmlWriter _writer = null;
1499         private TextWriter _stream = null;
1500 
CustomWriter(TextWriter stream, XmlWriterSettings xws)1501         public CustomWriter(TextWriter stream, XmlWriterSettings xws)
1502         {
1503             _stream = stream;
1504             _writer = XmlWriter.Create(stream, xws);
1505         }
1506 
WriteStartDocument()1507         public override void WriteStartDocument()
1508         {
1509             _writer.WriteStartDocument();
1510         }
1511 
WriteStartDocument(bool standalone)1512         public override void WriteStartDocument(bool standalone)
1513         {
1514             _writer.WriteStartDocument(standalone);
1515         }
1516 
WriteEndDocument()1517         public override void WriteEndDocument()
1518         {
1519             _writer.WriteEndDocument();
1520         }
1521 
WriteDocType(string name, string pubid, string sysid, string subset)1522         public override void WriteDocType(string name, string pubid, string sysid, string subset)
1523         {
1524             _writer.WriteDocType(name, pubid, sysid, subset);
1525         }
1526 
WriteStartElement(string prefix, string localName, string ns)1527         public override void WriteStartElement(string prefix, string localName, string ns)
1528         {
1529             _writer.WriteStartElement(prefix, localName, ns);
1530         }
1531 
WriteEndElement()1532         public override void WriteEndElement()
1533         {
1534             _writer.WriteEndElement();
1535         }
1536 
WriteFullEndElement()1537         public override void WriteFullEndElement()
1538         {
1539             _writer.WriteFullEndElement();
1540         }
1541 
WriteStartAttribute(string prefix, string localName, string ns)1542         public override void WriteStartAttribute(string prefix, string localName, string ns)
1543         {
1544             _writer.WriteStartAttribute(prefix, localName, ns);
1545         }
1546 
WriteEndAttribute()1547         public override void WriteEndAttribute()
1548         {
1549             _writer.WriteEndAttribute();
1550         }
1551 
WriteCData(string text)1552         public override void WriteCData(string text)
1553         {
1554             _writer.WriteCData(text);
1555         }
1556 
WriteComment(string text)1557         public override void WriteComment(string text)
1558         {
1559             _writer.WriteComment(text);
1560         }
1561 
WriteProcessingInstruction(string name, string text)1562         public override void WriteProcessingInstruction(string name, string text)
1563         {
1564             _writer.WriteProcessingInstruction(name, text);
1565         }
1566 
WriteEntityRef(string name)1567         public override void WriteEntityRef(string name)
1568         {
1569             _writer.WriteEntityRef(name);
1570         }
1571 
WriteCharEntity(char ch)1572         public override void WriteCharEntity(char ch)
1573         {
1574             _writer.WriteCharEntity(ch);
1575         }
1576 
WriteWhitespace(string ws)1577         public override void WriteWhitespace(string ws)
1578         {
1579             _writer.WriteWhitespace(ws);
1580         }
1581 
WriteString(string text)1582         public override void WriteString(string text)
1583         {
1584             _writer.WriteString(text);
1585         }
1586 
WriteSurrogateCharEntity(char lowChar, char highChar)1587         public override void WriteSurrogateCharEntity(char lowChar, char highChar)
1588         {
1589             _writer.WriteSurrogateCharEntity(lowChar, highChar);
1590         }
1591 
WriteChars(char[] buffer, int index, int count)1592         public override void WriteChars(char[] buffer, int index, int count)
1593         {
1594             _writer.WriteChars(buffer, index, count);
1595         }
1596 
WriteRaw(char[] buffer, int index, int count)1597         public override void WriteRaw(char[] buffer, int index, int count)
1598         {
1599             _writer.WriteRaw(buffer, index, count);
1600         }
1601 
WriteRaw(string data)1602         public override void WriteRaw(string data)
1603         {
1604             _writer.WriteRaw(data);
1605         }
1606 
WriteBase64(byte[] buffer, int index, int count)1607         public override void WriteBase64(byte[] buffer, int index, int count)
1608         {
1609             _writer.WriteBase64(buffer, index, count);
1610         }
1611 
1612         public override WriteState WriteState
1613         {
1614             get
1615             {
1616                 return _writer.WriteState;
1617             }
1618         }
1619 
1620         public override XmlSpace XmlSpace
1621         {
1622             get
1623             {
1624                 return _writer.XmlSpace;
1625             }
1626         }
1627 
1628         public override string XmlLang
1629         {
1630             get
1631             {
1632                 return _writer.XmlLang;
1633             }
1634         }
1635 
Dispose()1636         public new void Dispose()
1637         {
1638             _writer.Dispose();
1639             _stream.Dispose();
1640         }
1641 
Flush()1642         public override void Flush()
1643         {
1644             _writer.Flush();
1645         }
1646 
LookupPrefix(string ns)1647         public override string LookupPrefix(string ns)
1648         {
1649             return _writer.LookupPrefix(ns);
1650         }
1651     }
1652 }
1653