Esempio n. 1
0
 // Validates that the elements named in 'args' in WebKit can be converted
 // from HTML back into ECMA XML.
 //
 // Returns null on success, otherwise a string with the error details
 //
 public string ValidateElements(IWebView web, params string [] args)
 {
     foreach (var arg in args)
     {
         try {
             var str = web.Fetch(arg);
             DocConverter.ToXml(str, canonical: true);
             web.RunJS("postOk", arg);
         } catch (UnsupportedElementException e) {
             web.RunJS("postError", arg);
             return("Parsing error: " + e.Message);
         } catch (StackOverflowException e) {
             return("Exception " + e.GetType().ToString());
         }
     }
     return(null);
 }
Esempio n. 2
0
        //
        // Updates the target XElement with the edited text.
        // The first pass uses the provided xpath expression to remove all the nodes that match
        // this expression from the target (this cleans the nodes that we are about to replace)
        // then the named htmlElement is used to lookup the contents on WebKit and the results
        // are converted back to XML which is stashed in the target specified by xpath.
        //
        // Returns true on success
        public bool UpdateNode(IWebView webView, XElement target, string xpath, string htmlElement, out string error)
        {
            error = null;
            var node = target.XPathSelectElement(xpath);

            node.RemoveNodes();

            try {
                var str = webView.Fetch(htmlElement);
                foreach (var ret in DocConverter.ToXml(str, canonical: true))
                {
                    node.Add(ret);
                }
            } catch (UnsupportedElementException e) {
                error = e.Message;
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
    static void Process(XDocument d, string path)
    {
        var elements = d.XPathSelectElements(path);

        foreach (var element in elements)
        {
            var str = element.ToString();
            //Console.WriteLine (str);
            var html = DocConverter.ToHtml(element, currentFile, Path.GetDirectoryName(path));
            var ret  = DocConverter.ToXml(html);

            var sb = new StringBuilder();
            foreach (var c in element.Nodes())
            {
                sb.Append(c.ToString());
            }
            var expected = sb.ToString();
            //estr = estr.Replace (" />", "/>");
            sb.Clear();
            foreach (var c in ret)
            {
                try {
                    if (c is XComment)
                    {
                        sb.Append((c as XComment).Value);
                    }
                    else
                    {
                        sb.Append(c.ToString());
                    }
                } catch (ArgumentException e) {
                    // An XML comment cannot end with "-" looks like a bug
                }
            }
            var result = sb.ToString();

            if (expected != result)
            {
                var diff      = new XmlDiff(XmlDiffOptions.IgnoreWhitespace);
                var xexpected = new XmlTextReader(new StringReader("<group>" + expected + "</group>"));
                var xresult   = new XmlTextReader(new StringReader("<group>" + result + "</group>"));

                var equal = diff.Compare(xexpected, xresult);                  //, new XmlTextWriter (Console.Out));


                if (!equal && expected != result)
                {
                    bool found = false;
                    for (int i = 0; i < expected.Length && i < result.Length; i++)
                    {
                        if (expected [i] != result [i])
                        {
                            Report(expected, result, i);

                            // We redo the steps above, purely as it is easier to debug what happened right after
                            // the error is reported.
                            html  = DocConverter.ToHtml(element, currentFile, Path.GetDirectoryName(path));
                            ret   = DocConverter.ToXml(html);
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        Report(expected, result, Math.Min(expected.Length, result.Length));
                    }
                }
            }
        }
    }