//public static void TraceHtmlReader_v4(string file, bool generateCloseTag = false, bool disableLineColumn = false, bool disableScriptTreatment = false, // bool useReadAttributeValue_v2 = true, bool useTranslateChar = true) public static void TraceHtmlReader_v4(string file, HtmlReaderOptions options = HtmlReaderOptions.Default) { string traceFile = GetFile(file, ".trace.v4.txt"); Trace.WriteLine("HtmlReader v4"); Trace.WriteLine(" file \"{0}\"", file); Trace.WriteLine(" trace \"{0}\"", traceFile); //HtmlReader_v4.ReadFile(file, generateCloseTag: generateCloseTag, disableLineColumn: disableLineColumn, disableScriptTreatment: disableScriptTreatment, // useReadAttributeValue_v2: useReadAttributeValue_v2, useTranslateChar: useTranslateChar) // .zSave(traceFile); HtmlReader_v4.ReadFile(file, options: options).zSave(traceFile); }
//public static IEnumerable<HtmlNode> ReadString(string html, bool generateCloseTag = false, bool disableLineColumn = false, // bool disableScriptTreatment = false, bool useReadAttributeValue_v2 = true, bool useTranslateChar = true) public static IEnumerable <HtmlNode> ReadString(string html, HtmlReaderOptions options = HtmlReaderOptions.Default) { using (StringReader sr = new StringReader(html)) { // attention return Read() generate exception Cannot read from a closed TextReader. (System.ObjectDisposedException) //return Read(sr, generateCloseTag, disableLineColumn, disableScriptTreatment, useReadAttributeValue_v2, useTranslateChar); //foreach (HtmlNode node in Read(sr, generateCloseTag, disableLineColumn, disableScriptTreatment, useReadAttributeValue_v2, useTranslateChar)) foreach (HtmlNode node in Read(sr, options)) { yield return(node); } } }
public static IEnumerable <HtmlDocNode> Read(TextReader textReader) { HtmlDocReader reader = new HtmlDocReader(); //bool disableLineColumn = false; //bool disableScriptTreatment = false; //bool useReadAttributeValue_v2 = true; //bool useTranslateChar = true; //reader._nodes = HtmlReader_v4.Read(textReader, generateCloseTag: true, disableLineColumn: disableLineColumn, disableScriptTreatment: disableScriptTreatment, // useReadAttributeValue_v2: useReadAttributeValue_v2, useTranslateChar: useTranslateChar); HtmlReaderOptions options = HtmlReaderOptions.Default | HtmlReaderOptions.GenerateCloseTag; reader._nodes = HtmlReader_v4.Read(textReader, options); return(reader.Read()); }
//HtmlReaderOptions //public static IEnumerable<HtmlNode> Read(TextReader textReader, bool generateCloseTag = false, bool disableLineColumn = false, // bool disableScriptTreatment = false, bool useReadAttributeValue_v2 = true, bool useTranslateChar = true, bool useFilterChar = true) public static IEnumerable <HtmlNode> Read(TextReader textReader, HtmlReaderOptions options = HtmlReaderOptions.Default) { //HtmlReader_v4 htmlReader = new HtmlReader_v4(textReader, useTranslateChar, useFilterChar); HtmlReader_v4 htmlReader = new HtmlReader_v4(textReader, options); ////htmlReader.GenerateCloseTag = generateCloseTag; //htmlReader.GenerateCloseTag = (options & HtmlReaderOptions.GenerateCloseTag) == HtmlReaderOptions.GenerateCloseTag; ////htmlReader.DisableLineColumn = disableLineColumn; //htmlReader.DisableLineColumn = (options & HtmlReaderOptions.DisableLineColumn) == HtmlReaderOptions.DisableLineColumn; ////htmlReader.DisableScriptTreatment = disableScriptTreatment; //htmlReader.DisableScriptTreatment = (options & HtmlReaderOptions.DisableScriptTreatment) == HtmlReaderOptions.DisableScriptTreatment; ////htmlReader.UseReadAttributeValue_v2 = useReadAttributeValue_v2; //htmlReader.TextReplaceControl = (options & HtmlReaderOptions.TextReplaceControl) == HtmlReaderOptions.TextReplaceControl; return(htmlReader.Read()); }
//public HtmlReader_v4(TextReader textReader, bool useTranslateChar = true, bool useFilterChar = true) public HtmlReader_v4(TextReader textReader, HtmlReaderOptions options = HtmlReaderOptions.Default) { _charStreamReader = new CharStreamReader(textReader); //if (useTranslateChar) if ((options & HtmlReaderOptions.UseTranslateChar) == HtmlReaderOptions.UseTranslateChar) { _charStreamReader.TranslateChar = TranslateChar; } //if (useFilterChar) if ((options & HtmlReaderOptions.UseFilterChar) == HtmlReaderOptions.UseFilterChar) { _charStreamReader.FilterChar = FilterChar; } _generateCloseTag = (options & HtmlReaderOptions.GenerateCloseTag) == HtmlReaderOptions.GenerateCloseTag; _disableLineColumn = (options & HtmlReaderOptions.DisableLineColumn) == HtmlReaderOptions.DisableLineColumn; _disableScriptTreatment = (options & HtmlReaderOptions.DisableScriptTreatment) == HtmlReaderOptions.DisableScriptTreatment; _textReplaceControl = (options & HtmlReaderOptions.TextReplaceControl) == HtmlReaderOptions.TextReplaceControl; }
public static void FileHtmlToXml_v2(string file, string xmlFile, bool traceHtmlReader = false, bool traceHtmlToXml = false) { //HtmlReaderOptions options = HtmlReaderOptions.Default | HtmlReaderOptions.GenerateCloseTag; HtmlReaderOptions options = HtmlReaderOptions.Default; if (traceHtmlReader) { HtmlReader_v4.ReadFile(file, options: options | HtmlReaderOptions.DisableLineColumn).zSave(GetFile(file, ".HtmlReader.v4.txt"), jsonIndent: true); } using (StreamReader sr = zfile.OpenText(file)) { HtmlReader_v4 htmlReader = new HtmlReader_v4(sr, options); HtmlToXml_v3 htmlToXml = new HtmlToXml_v3(htmlReader); htmlToXml.CreateXml().Save(xmlFile); if (traceHtmlToXml) { htmlToXml.Log.zSave(GetFile(file, ".HtmlToXml.v2.json")); } } }