//[Test] public void ReadOnlyReturnsLegalXmlCharacters() { // This should be stripped to "\t\r\n<>:" string xml = "\0\t\a\r\b\n<>:"; // Load the XML as a Stream using (var buffer = new MemoryStream(System.Text.Encoding.Default.GetBytes(xml))) { using (var sanitizer = new XmlSanitizingStream(buffer)) { var t = sanitizer.Read(); t = sanitizer.Read(); t = sanitizer.Read(); t = sanitizer.Read(); t = sanitizer.Read(); t = sanitizer.Read(); t = sanitizer.Read(); t = sanitizer.Read(); var y = sanitizer.EndOfStream; /*Assert.AreEqual(sanitizer.Read(), '\t'); * Assert.AreEqual(sanitizer.Read(), '\r'); * Assert.AreEqual(sanitizer.Read(), '\n'); * Assert.AreEqual(sanitizer.Read(), '<'); * Assert.AreEqual(sanitizer.Read(), '>'); * Assert.AreEqual(sanitizer.Read(), ':'); * Assert.AreEqual(sanitizer.Read(), -1); * Assert.IsTrue(sanitizer.EndOfStream);*/ } } using (var buffer = new MemoryStream(System.Text.Encoding.Default.GetBytes(xml))) { using (var sanitizer = new XmlSanitizingStream(buffer)) { //Assert.AreEqual(sanitizer.ReadToEnd(), "\t\r\n<>:"); } } } // method
public override int Read() { // Read each character, skipping over characters that XML has prohibited int nextCharacter; do { // Read a character if ((nextCharacter = base.Read()) == EOF) { // If the character denotes the end of the file, stop reading break; } } // Skip the character if it's prohibited, and try the next while (!XmlSanitizingStream.IsLegalXmlChar(nextCharacter)); return(nextCharacter); }
public override int Peek() { // Return the next legl XML character without reading it int nextCharacter; do { // See what the next character is nextCharacter = base.Peek(); }while ( // If it's prohibited XML, skip over the character in the stream // and try the next. !XmlSanitizingStream.IsLegalXmlChar(nextCharacter) && (nextCharacter = base.Read()) != EOF ); return(nextCharacter); } // method
/// <summary> /// Get whether an integer represents a legal XML 1.0 character. See the /// specification at w3.org for these characters. /// </summary> public static bool IsLegalXmlChar(int character) { return(XmlSanitizingStream.IsLegalXmlChar("1.1", character)); }