Beispiel #1
0
        public void Test_GetDocumentFragmentByXPath_1()
        {
            string name   = "testpage5.html.zip";
            string xpath  = ".//p";
            string folder = StorageTestDataPath;

            var response = HtmlApi.GetDocumentFragmentByXPath(name, xpath, "plain", null, folder);

            checkGetMethodResponse(response, "Document", "_xpath_p");
        }
Beispiel #2
0
        public void Test_GetDocumentFragmentByXPath_2()
        {
            string name   = "testpage1.html";
            string xpath  = ".//ol/li";
            string folder = StorageTestDataPath;

            var response = HtmlApi.GetDocumentFragmentByXPath(name, xpath, "json", null, folder);

            checkGetMethodResponseOkOrNoresult(response, "Document", "_xpath_ol_li");
        }
        public void Run()
        {
            // setup HTML document name
            var name = "testpage3_embcss.html";
            // setup XPath query to select fragments
            var xPath = "//ol/li";
            // setup storage folder path where is the source document
            var folder = CommonSettings.StorageDataFolder;
            // Upload source file to cloud storage
            var srcPath     = Path.Combine(CommonSettings.LocalDataFolder, name);
            var storagePath = Path.Combine(folder, name).Replace('\\', '/');

            if (File.Exists(srcPath))
            {
                SdkBaseRunner.UploadToStorage(storagePath, srcPath);
            }
            else
            {
                throw new Exception(string.Format("Error: file {0} not found.", srcPath));
            }

            IDocumentApi docApi = new HtmlApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath);
            // call the SDK method that returns a query result in the response stream.
            var response = docApi.GetDocumentFragmentByXPath(name, xPath, "json", null, folder);

            if (response != null && response.ContentStream != null)
            {
                if (response.Status == "NoContent")
                {
                    Console.WriteLine("Operation succeeded but result is empty");
                }
                else if (response.Status == "OK")
                {
                    Stream stream  = response.ContentStream;
                    string outFile = response.FileName;
                    string outPath = Path.Combine(CommonSettings.OutDirectory, outFile);
                    using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write))
                    {
                        stream.Position = 0;
                        stream.CopyTo(fstr);
                        fstr.Flush();
                        Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath));
                    }
                }
            }
        }