将 XML、XSL 创建的 HTML 转换为 MHTML

发布于 2025-01-08 05:14:24 字数 2163 浏览 0 评论 0原文

浏览器可以使用 XSL 来转换 XML。 这可以通过在 xml 中引用 xsl 来完成 在 xml 文件中添加以下行:

现在使用 Internet Explorer 打开此 xml 文件将显示浏览器中的数据正确。

XML 本身引用了许多其他文件,例如位于某个文件夹中的图片。

我想将显示的数据(以及所有引用的数据)保存在一个单独的数据中 mhtml 文件 (*.mht)

我该如何继续?这可能吗?

注意:文件都是本地的(不在服务器上),初始的 xml 是测试数据的结果。 我只是希望我的 XML 文件能够像以前一样从单个文件开始正确显示,而无需访问 mhtml 文件之外的其他数据。

根据答案 1 进行编辑

我已将 xml 包含在 HTML 的 iFrame 中:

我已使用 IE 将其保存到 *.mht 文件中:

From: <Saved by Windows Internet Explorer 7>
Subject: XML-Test
Date: Wed, 22 Feb 2012 14:47:34 +0100
MIME-Version: 1.0
Content-Type: multipart/related;
    boundary="----=_NextPart_000_0000_01CCF170.E99B1DF0"
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157

This is a multi-part message in MIME format.

------=_NextPart_000_0000_01CCF170.E99B1DF0
Content-Type: text/html;
    charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Content-Location: file://C:\Documents and Settings\STEFFAN\Desktop\Test\XML-Test.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>XML-Test</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 6.00.6000.17107" name=3DGENERATOR></HEAD>
<BODY><IFRAME=20
src=3D"http://www.m.de/name.xml"=20
width=3D"100%" height=3D1000>
</IFRAME></BODY></HTML>

------=_NextPart_000_0000_01CCF170.E99B1DF0
Content-Type: text/xml;
    charset="unicode"
Content-Transfer-Encoding: base64
Content-Location: http://www.m.de/name.xml

//48ACEARABPAEMAVABZAFAARQAgAEgAVABNAEwAIABQAFUAQgBMAEkAQwAgACIALQAvAC8AVwAz
AEMALwAvAEQAVABEACAASABUAE0ATAAgADQALgAwACAAVAByAGEAbgBzAGkAdABpAG8AbgBhAGwA...

因为我最初使用本地文件而不是“http://www.m.de/name.xml”“file://C:\Documents 和Settings\STEFFAN\Desktop\Test\SUPL_TCLog.xml”由IE输出。

但这个本地引用似乎不适用于 mhtml,这很糟糕,因此,我使用了一个随机替代品 (http://www.m.de/name.xml) 来代替它。 (这对于图像文件来说效果很好)。相应地更改它,打开 mht 文件将开始下载 xml 文件。但这不是我们想要的。我想让它显示出来。

缺什么?

XML's can be transformed by a browser using XSL.
This can be either done by referencing an xsl within the xml by
adding the following line within the xml file:

<?xml-stylesheet type='text/xsl' href='sample.xsl'?>

Opening this xml file now with internet explorer will display the correct data in the browser.

The XML itself references many other files as e.g. pictures which are located in some folder.

I want to save the data displayed (with all the referenced data) in one single
mhtml file (*.mht)

How do I proceed? And is this possible?

Note: Files are all local (not on a server) and the initial xml is a result of test data.
I just want my XML file to be displayed correctly as before started from a single file without accessing other data outside the mhtml file.

Edit upon answer 1:

I have included my xml within an iFrame of an HTML:

<body><iframe src="name.xml" width = "100%" height="1000">
</iframe></body>

This I have saved using IE into an *.mht file:

From: <Saved by Windows Internet Explorer 7>
Subject: XML-Test
Date: Wed, 22 Feb 2012 14:47:34 +0100
MIME-Version: 1.0
Content-Type: multipart/related;
    boundary="----=_NextPart_000_0000_01CCF170.E99B1DF0"
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157

This is a multi-part message in MIME format.

------=_NextPart_000_0000_01CCF170.E99B1DF0
Content-Type: text/html;
    charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Content-Location: file://C:\Documents and Settings\STEFFAN\Desktop\Test\XML-Test.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>XML-Test</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 6.00.6000.17107" name=3DGENERATOR></HEAD>
<BODY><IFRAME=20
src=3D"http://www.m.de/name.xml"=20
width=3D"100%" height=3D1000>
</IFRAME></BODY></HTML>

------=_NextPart_000_0000_01CCF170.E99B1DF0
Content-Type: text/xml;
    charset="unicode"
Content-Transfer-Encoding: base64
Content-Location: http://www.m.de/name.xml

//48ACEARABPAEMAVABZAFAARQAgAEgAVABNAEwAIABQAFUAQgBMAEkAQwAgACIALQAvAC8AVwAz
AEMALwAvAEQAVABEACAASABUAE0ATAAgADQALgAwACAAVAByAGEAbgBzAGkAdABpAG8AbgBhAGwA...

Since I use local files originally instead of "http://www.m.de/name.xml" "file://C:\Documents and Settings\STEFFAN\Desktop\Test\SUPL_TCLog.xml" was outputted by IE.

But this local reference does not seem to work for mhtml, which sucks and therefore, I used a random substitute (http://www.m.de/name.xml) for it. (this works fine for image files). Changing it accordingly opening the mht file will start a download of the xml file. But this is not wanted. I want it to be displayed.

What is missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

榕城若虚 2025-01-15 05:14:24

这是可能的,但您必须自己构建一些东西。

MHTML 本质上是一个多部分电子邮件。 RFC-2557 完整描述了其格式。它可以由电子邮件消息生成器和序列化器生成。

但是我不知道有任何工具可以以编程方式生成 MHTML。还要注意的是,没有一种标准的 Web 存档格式(至少有四种),并且只有 IE、Opera 和 Chrome 可以读取 MHTML。

最简单的方法是编写 IE 脚本来打开页面并将其另存为 MHTML。

如果您想在没有 IE 的情况下生成 MHTML,那么您需要创建一个 MHTML 存档器。

对于归档器,最简单的做法是:

  1. 包含所有可能的外部资源,
  2. 确保所有这些资源始终由相同的 url 引用
  3. ,然后为该资源使用匹配的 content-location

这样,您无需重写 hrefsrc 属性或解析 xsl 或 html 来发现要包含哪些资源。

如果可能的外部资源太多或者无法一致地使用路径,则需要进行资源发现和/或 url 重写的解析。

在任何情况下,您都可以保存 xml+xsl,也可以先生成 HTML 输出并保存。

This is possible, but you will have to build some things yourself.

MHTML is essentially a multipart email message. Its format is fully described by RFC-2557. It can be generated by email message generators and serializers.

However I am unaware of any tool that will generate MHTML programmatically. Be warned, too, that there is no one standard web archive format (there are at least four), and only IE, Opera, and Chrome can read MHTML.

The simplest thing that can work is to script IE to open your page and save it as MHTML.

If you want to generate MHTML without IE, then you need to create an MHTML archiver.

With an archiver, the simplest thing to do is to:

  1. include all possible external resources
  2. make sure all those resources are always referenced by the same url
  3. then use a matching content-location for that resource.

This way you do not need to rewrite href and src attributes or parse your xsl or html to discover what resources to include.

If there are too many possible external resources or you can't use paths consistently, you will need to do parsing for resource discovery and/or url rewriting.

In any scenario you can either save the xml+xsl, or you can generate the HTML output first and save that.

所有深爱都是秘密 2025-01-15 05:14:24

我确实尝试了一些尝试,但没有成功。
另外弗朗西斯·阿维拉的提案我也无法成功解决。

特别是 javascript 引用的代码还包含其他引用。我不知道如何解决这些并将它们放入 mhtml 中。

也许使用 Altova StyleVision 是一个解决方案。

因为我不再尝试了。我关闭这个线程。

I did try some attempts, but was not successful.
Also Francis Avila's proposal I could not solve successful.

Especially code referenced by javascript also contained other references. I did not know how to resolve these and put them into mhtml.

Maybe using Altova StyleVision would be a solution.

Since I did not longer try. I close this thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文