protected override EpubEntrySearchResults searchEpubEntry(String entryName, Stream stream)
        {
            XmlDocument xmlDocument = SgmlDocuments.readHtmlAsXmlDocument(stream);                     // EPUB uses XHTML not HTML, but let's be forgiving

            if (null == xmlDocument)
            {
                Console.Error.WriteLine("Error: could not parse: {0}", entryName);
                return(null);
            }

            // TODO: switch to using XPathNavigator

            IEnumerable <Tuple <XmlNode, MatchCollection> > xmlNodeMatchCollections = xmlDocument.SelectNodes(xpath.Expression).matchWithinAll(regex);

            if (xmlNodeMatchCollections.isNullOrEmpty())
            {
                return(null);
            }

            XmlNode titleXmlNode = xmlDocument.SelectSingleNode(".//title");
            String  entryTitle   = (null == titleXmlNode) ? null : titleXmlNode.InnerText.Trim();

            return(new EpubEntrySearchResults(entryName, entryTitle, xmlNodeMatchCollections.Select(t => new XmlNodeSearchResults(t.Item1.Name, new RegexSearchResultMatchCollection(t.Item2)))));
        }
Exemple #2
0
        public static XmlDocument postFormDataReturnXmlDocument(this WebClient thisWebClient, String uriString, NameValueCollection nameValueCollection)
        {
            String responseString = thisWebClient.postFormDataReturnString(uriString, nameValueCollection);

            return(SgmlDocuments.readHtmlAsXmlDocument(responseString));
        }
Exemple #3
0
 public static XmlDocument getXmlDocument(this WebClient thisWebClient, Uri uri)
 {
     using (Stream stream = thisWebClient.OpenRead(uri)) {
         return(SgmlDocuments.readHtmlAsXmlDocument(stream));
     }
 }