public static RICResponse RequestData(RICRequest request) { if (Connected) { try { Writer.WriteWithEndBlock(request.ToString()); return(RICResponse.Parse(Reader.ReadToEndBlock().Replace(((char)0).ToString(), ""))); } catch (Exception e) { if (e is SocketException || e is IOException) { return(RICResponse.Text("CONNECTION_ERROR")); } else { throw; } } } else { return(RICResponse.Text("CONNECTION_ERROR")); } }
public static RICResponse Parse(string xml) { var result = new RICResponse(); using (var reader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(xml)))) while (!reader.EOF) { if (reader.IsStartElement("Article")) { result.Data.Add(Article.Parse(reader.ReadOuterXml())); } else if (reader.IsStartElement("Text")) { result.Data.Add(reader.ReadElementContentAsString()); } else { reader.Read(); } } return(result); }