コード例 #1
0
ファイル: DocModel.cs プロジェクト: yerumaku/DocWriter
 // 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);
 }
コード例 #2
0
ファイル: DocModel.cs プロジェクト: yerumaku/DocWriter
        //
        // 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);
        }