Esempio n. 1
0
        /// <summary>
        /// Deserialize a HTML document
        /// </summary>
        public HDocument DeserializeDocument(TextReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            // Create result
            HDocument result = new HDocument();

            result.Encoding = null;
            // Load nodes in the document
            result.Add(Deserialize(reader, err => {
                if (err is ParseError)
                {
                    result.AddParseError((ParseError)err);
                    return(true);
                }
                return(false);
            }));
            // Check encoding
            if (result.Encoding == null)
            {
                if (reader is StreamReader)
                {
                    result.Encoding = ((StreamReader)reader).CurrentEncoding;
                }
                else
                {
                    result.Encoding = Encoding.UTF8;
                }
            }
            return(result);
        }
Esempio n. 2
0
 /// <summary>
 /// Direct serialization of a HTML document to string
 /// </summary>
 public String Serialize(HDocument html)
 {
     if (html == null)
     {
         throw new ArgumentNullException("html");
     }
     return(SerializeNode(html));
 }
Esempio n. 3
0
 /// <summary>
 /// Serialise an HTML document
 /// </summary>
 public void Serialize(HDocument html, TextWriter writer)
 {
     if (html == null)
     {
         throw new ArgumentNullException("html");
     }
     if (writer == null)
     {
         throw new ArgumentNullException("writer");
     }
     SerializeNode(html, writer);
 }
Esempio n. 4
0
 /// <summary>
 /// Internal document serialization
 /// </summary>
 protected virtual void SerializeDocument
     (HDocument html, TextWriter writer)
 {
     SerializeContainer(html, writer);
 }
Esempio n. 5
0
 /// <summary>
 /// Create a new HTML document from another.
 /// </summary>
 public HDocument(HDocument other)
     : base(other)
 {
     this.Encoding = other.Encoding;
 }