Windows.Data.Xml.Xsl.XsltProcessor抛出HRESULT E_FAIL COM异常 [英] Windows.Data.Xml.Xsl.XsltProcessor throws a HRESULT E_FAIL COM exception

查看:41
本文介绍了Windows.Data.Xml.Xsl.XsltProcessor抛出HRESULT E_FAIL COM异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用xsl文件加载XSLT处理器时,我获得了类似于其他用户在尝试调用TransformToString()时所遇到的COM激活。 XSLT代码有效。这是我使用的代码:


StorageFile XMLFILE =等待KnownFolders.DocumentsLibrary.GetFileAsync(xmlPathInternal);

    &NBSP ;           Windows.Data.Xml.Dom.XmlDocument xmlDoc中=等待Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(XMLFILE);


                 //阅读XSLT

                StorageFile xslFile =等待KnownFolders.DocumentsLibrary.GetFileAsync(xslPathInternal);

              &NBSP ; Windows.Data.Xml.Dom.XmlDocument列名为xsldoc =等待Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(xslFile);


                 //在XML上应用XSLT

                Windows.Data.Xml.Xsl.XsltProcessor处理器=新Windows.Data.Xml.Xsl.XsltProcessor(列名为xsldoc);

解决方案

您好Dmitri,


我可以知道您使用的是哪个孩子用于TransformToString()方法,我正在使用以下代码进行测试,如果您尝试转换第一个代码,它对我来说很好用节点到字符串,它将失败,因为它不是真正的XML节点,只有
XML样式表声明。


来自W3School的XSLT代码,有效。

<?xml version =" 1.0"编码= QUOT; ISO-8859-1"?> 
<! - 由XMLSpy®编辑 - >
< xsl:stylesheet version =" 1.0"的xmlns:XSL = QUOT; HTTP://www.w3.org/1999/XSL/Transform">

< xsl:template match =" /">
< html>
< body>
< h2>我的CD收藏< / h2>
< table border =" 1">
< tr bgcolor ="#9acd32">
< th>标题< / th>
< th>艺术家< / th>
< / tr>
< xsl:for-each select =" catalog / cd">
< tr>
< td>< xsl:value-of select =" title" />< / td>
< td>< xsl:value-of select =" artist" />< / td>
< / tr>
< / xsl:for-each>
< / table>
< / body>
< / html>
< / xsl:template>
< / xsl:stylesheet>

App中的C#代码

 public async void kkk( )
{
//读取XSLT
StorageFile xslFile =等待KnownFolders.MusicLibrary.GetFileAsync(QUOT; 1.xslt");
Windows.Data.Xml.Dom.XmlDocument xslDoc = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(xslFile);

//在XML上应用XSLT
Windows.Data.Xml.Xsl.XsltProcessor processor = new Windows.Data.Xml.Xsl.XsltProcessor(xslDoc);
if(xslDoc.HasChildNodes())
{
string aaa = processor.TransformToString(xslDoc.ChildNodes [1]);
}

}

- James



When trying to load the XSLT processor with an xsl file, I get a COM excpetion similar to what other users have experienced when trying to call TransformToString(). The XSLT code is valid. This is the code that I am using:

StorageFile xmlFile = await KnownFolders.DocumentsLibrary.GetFileAsync(xmlPathInternal);
                Windows.Data.Xml.Dom.XmlDocument xmlDoc = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(xmlFile);

                // Read XSLT
                StorageFile xslFile = await KnownFolders.DocumentsLibrary.GetFileAsync(xslPathInternal);
                Windows.Data.Xml.Dom.XmlDocument xslDoc = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(xslFile);

                // Apply XSLT on XML
                Windows.Data.Xml.Xsl.XsltProcessor processor = new Windows.Data.Xml.Xsl.XsltProcessor(xslDoc);

解决方案

Hi Dmitri,

May I know which child are you using for TransformToString() method, I'm testing with the following code and it works fine for me, if you are trying to convert the first node to string, it will fail with COM exception because it is not a real XML node, only the XML Style Sheet Declaration.

XSLT code from W3School, valid.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

C# code in App

        public async void kkk()
        {
            // Read XSLT
            StorageFile xslFile = await KnownFolders.MusicLibrary.GetFileAsync("1.xslt");
            Windows.Data.Xml.Dom.XmlDocument xslDoc = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(xslFile);

            // Apply XSLT on XML
            Windows.Data.Xml.Xsl.XsltProcessor processor = new Windows.Data.Xml.Xsl.XsltProcessor(xslDoc);
            if(xslDoc.HasChildNodes())
            {
                string aaa = processor.TransformToString(xslDoc.ChildNodes[1]);
            }

        }

--James


这篇关于Windows.Data.Xml.Xsl.XsltProcessor抛出HRESULT E_FAIL COM异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆