/// <summary> /// As XmlReader is forward only and we added support for leaving xmlisland data. /// We have to use another xmlreader to find TocTile, keywords etc. /// </summary> /// <param name="filename"></param> private void ReadXmlIsland(XmlReader reader) { //Fix TFS bug 289403: search if there is comma in k keyword except those in () or <>. //sample1: "StoredNumber (T1,T2) class, about StoredNumber (T1,T2) class"; //sample2: "StoredNumber <T1,T2> class, about StoredNumber <T1,T2> class"; while (reader.Read()) { if (reader.IsStartElement()) { if (reader.Name.ToLower() == "mshelp:toctitle") { string titleAttr = reader.GetAttribute("Title"); if (!String.IsNullOrEmpty(titleAttr)) { _currentTitle = titleAttr; } } if (reader.Name.ToLower() == "mshelp:keyword") { string indexType = reader.GetAttribute("Index"); if (indexType == "K") { string kkeyword = reader.GetAttribute("Term"); if (!string.IsNullOrEmpty(kkeyword)) { KKeywordInfo kkwdinfo = new KKeywordInfo(); kkeyword = FormatChmHelper.ReplaceMarks(kkeyword); Match match = _regEx.Match(kkeyword); if (match.Success) { kkwdinfo.MainEntry = kkeyword.Substring(0, match.Index); kkwdinfo.SubEntry = kkeyword.Substring( match.Index + 1).TrimStart(new char[] { ' ' }); } else { kkwdinfo.MainEntry = kkeyword; } kkwdinfo.File = _currentFile; _kkeywords.Add(kkwdinfo); } } } } if (reader.NodeType == XmlNodeType.EndElement) { if (reader.Name == "xml") { break; } } } }
/// <summary> /// As XmlReader is forward only and we added support for leaving xmlisland data. /// We have to use another xmlreader to find TocTile, keywords etc. /// </summary> /// <param name="filename"></param> private void ReadXmlIsland(XmlReader reader, XmlWriter writer) { string nodeName = null; XmlNodeType nodeType = XmlNodeType.None; while (reader.Read()) { nodeType = reader.NodeType; nodeName = reader.Name; if (nodeType == XmlNodeType.Element) { if (String.Equals(nodeName, "mshelp:toctitle", StringComparison.OrdinalIgnoreCase)) { string titleAttr = reader.GetAttribute("Title"); if (!String.IsNullOrEmpty(titleAttr)) { _currentTitle = titleAttr; } } else if (String.Equals(nodeName, "mshelp:keyword", StringComparison.OrdinalIgnoreCase)) { string indexType = reader.GetAttribute("Index"); if (indexType == "K" || indexType == "A") { string kkeyword = reader.GetAttribute("Term"); if (!string.IsNullOrEmpty(kkeyword)) { //<meta name="MS-HKWD/MS-HAID" content="Keyword"/> //<meta name="MS-HKWD/MS-HAID" content="Keyword1, Keyword2"/> string indexWord = indexType == "K" ? "MS-HKWD" : "MS-HAID"; writer.WriteStartElement("meta"); writer.WriteAttributeString("name", indexWord); kkeyword = FormatChmHelper.ReplaceMarks(kkeyword); Match match = _regEx.Match(kkeyword); if (match.Success) { string keyText = kkeyword.Substring(0, match.Index); keyText += ", "; keyText += kkeyword.Substring( match.Index + 1).TrimStart(new char[] { ' ' }); writer.WriteAttributeString("content", keyText); } else { writer.WriteAttributeString("content", kkeyword); } writer.WriteEndElement(); } } } } else if (nodeType == XmlNodeType.EndElement) { if (String.Equals(nodeName, "xml")) { break; } } } }