当前位置: 首页>>代码示例>>C#>>正文


C# XDoc.ToXHtml方法代码示例

本文整理汇总了C#中XDoc.ToXHtml方法的典型用法代码示例。如果您正苦于以下问题:C# XDoc.ToXHtml方法的具体用法?C# XDoc.ToXHtml怎么用?C# XDoc.ToXHtml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XDoc的用法示例。


在下文中一共展示了XDoc.ToXHtml方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Export

        //--- Class Methods ---
        public static Stream Export(XDoc content) {
            // use authtoken for embedded images
            string authtoken = AuthBL.CreateAuthTokenForUser(DekiContext.Current.User);
          
            foreach(XDoc img in content["//img"]) {
                string src = img["@src"].AsText;
                if(StringUtil.StartsWithInvariant(src, "/")) {
                    src = DekiContext.Current.UiUri.Uri.SchemeHostPort + src;
                }

                if(StringUtil.StartsWithInvariantIgnoreCase(src, DekiContext.Current.UiUri.Uri.SchemeHostPort + "/") || 
                   StringUtil.StartsWithInvariantIgnoreCase(src, Utils.MKS_PATH))                    
                        img["@src"].ReplaceValue(new XUri(src).With("authtoken", authtoken));   
            }

            string doctype = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
            MemoryStream stdIn = new MemoryStream(Encoding.UTF8.GetBytes(doctype + content.ToXHtml()));
            Stream stdOut;
            Stream stdErr;
            int exitCode = 0;
            
            Tuplet<int, Stream, Stream> exitValues;

            if(DekiContext.Current.Deki.PrinceXmlPath != string.Empty) {
                try {
                    string args = string.Format("--input=xml -s {0} --baseurl={1} - -o -", DekiContext.Current.UiUri.AtPath("skins/common/prince.php"), DekiContext.Current.UiUri);
                    exitValues = Async.ExecuteProcess(DekiContext.Current.Deki.PrinceXmlPath, args, stdIn, new Result<Tuplet<int, Stream, Stream>>(TimeSpan.FromMilliseconds(DekiContext.Current.Deki.PrinceXmlTimeout))).Wait();
                    exitCode = exitValues.Item1;
                    stdOut = exitValues.Item2;
                    stdErr = exitValues.Item3;
                    if (exitCode != 0) {
                        string error = string.Empty;
                        using(StreamReader sr = new StreamReader(stdErr)) {
                            error = sr.ReadToEnd();
                        }
                        DekiContext.Current.Instance.Log.DebugFormat("{0} failed with ExitCode: {1}, stdErr: {2}", DekiContext.Current.Deki.PrinceXmlPath, exitCode, error);
                        return null;
                    }
                    return stdOut.ToChunkedMemoryStream(-1, new Result<ChunkedMemoryStream>()).Wait();
                } catch (Exception e) {
                    DekiContext.Current.Instance.Log.Error("Error converting PDF", e);
                }
            }
            return null;
        } 
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:46,代码来源:Export.cs

示例2: Format

 public Stream Format(XDoc doc)
 {
     // TODO (steveb): convert XML to XHTML without generating a string first
     var bytes = MimeType.XHTML.CharSet.GetBytes(doc.ToXHtml());
     return new MemoryStream(bytes);
 }
开发者ID:heran,项目名称:DReAM,代码行数:6,代码来源:ioformatter.cs

示例3: XmlNullChar_in_xml_attribute_ToXHtml

 public void XmlNullChar_in_xml_attribute_ToXHtml()
 {
     var doc = new XDoc("root").Attr("name", "foo\0bar");
     Assert.AreEqual("<root name=\"foobar\"></root>", doc.ToXHtml());
 }
开发者ID:bjorg,项目名称:DReAM,代码行数:5,代码来源:XDoc-Test.cs

示例4: XmlNullChar_in_xml_element_ToXHtml

 public void XmlNullChar_in_xml_element_ToXHtml()
 {
     var doc = new XDoc("root").Value("foo\0bar");
     Assert.AreEqual("<root>foobar</root>", doc.ToXHtml());
 }
开发者ID:bjorg,项目名称:DReAM,代码行数:5,代码来源:XDoc-Test.cs

示例5: CreatePrinceHtml

        private static string CreatePrinceHtml(XDoc content) {
            // use authtoken for embedded images
            string authtoken = AuthBL.CreateAuthTokenForUser(DekiContext.Current.User);

            foreach(XDoc img in content["//img"]) {
                string src = img["@src"].AsText;
                if(StringUtil.StartsWithInvariant(src, "/")) {
                    src = DekiContext.Current.UiUri.Uri.SchemeHostPort + src;
                }

                if(StringUtil.StartsWithInvariantIgnoreCase(src, DekiContext.Current.UiUri.Uri.SchemeHostPort + "/") ||
                   StringUtil.StartsWithInvariantIgnoreCase(src, Utils.MKS_PATH))
                    img["@src"].ReplaceValue(new XUri(src).With("authtoken", authtoken));
            }
            
            // prepend doctype so prince uses xhtml parser
            // need to use strings instead of XDoc since XDoc doesn't allow you to set a doctype
            string doctype = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
            return doctype + content.ToXHtml();
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:20,代码来源:Export.cs


注:本文中的XDoc.ToXHtml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。