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
private CatalogFolderModel ConvertToFolder(StringBuilder opdsSource, string url) { try { CatalogContentDto dto; using (var stringReader = new MemoryStream(Encoding.UTF8.GetBytes(opdsSource.ToString()))) { using (var sanitizingStream = new XmlSanitizingStream(stringReader)) { var xmlSerializer = new XmlSerializer(typeof(CatalogContentDto)); dto = (CatalogContentDto)xmlSerializer.Deserialize(sanitizingStream); } } var folder = dto.ToFolder(CatalogModel.Url, CatalogModel.Type, CatalogId); folder.BaseUrl = url; return folder; } catch (InvalidOperationException exp) { if (ValidateForHtmlContent(exp)) { throw new WrongCatalogFormatException(exp.Message, url); } throw new ReadCatalogException("Unable convert OPDS data to folder", exp); } }
/// <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.0", character)); }