问题是这样的,如果我把transformNode后的内容保存为html文件,然后用webbrowser去navigate这个文件,是对的,因为html文件里有这句:
<link href="2.css" rel="stylesheet" type="text/css" />
这个css文件和生成的html文件在一个目录下.
但如果我不保存html文件,直接用webbrowser显示transformNode后的内容,发现css没有起作用,
如果我把<link href="2.css" rel="stylesheet" type="text/css" />
里的2.css改成绝对路径,就对了.
因为我不想hardcopy一个绝对路径,也不想动态修改xml和xsl文件,应该怎么办?
<link href="2.css" rel="stylesheet" type="text/css" />
这个css文件和生成的html文件在一个目录下.
但如果我不保存html文件,直接用webbrowser显示transformNode后的内容,发现css没有起作用,
如果我把<link href="2.css" rel="stylesheet" type="text/css" />
里的2.css改成绝对路径,就对了.
因为我不想hardcopy一个绝对路径,也不想动态修改xml和xsl文件,应该怎么办?
HTML. You don't have to save it to disk, or make visible to the user,
just feed it in the stream with the rest of the content.Another way is to write a custom implementation of IMoniker interface.
You only need a non-trivial implementation of two methods: BindToStorage
should return the IStream with your HTML content, and GetDisplayName
should return the base URL you want to use to resolve relative links.
You then use IPersistMoniker to feed the content into MSHTML using this
custom implementation, instead of IPersistStreamInit. Disclaimer: I have
not done this myself, but I've seen people reporting successful use of
this technique.Changed your LoadFromStream method to QI on the WebBrowser Document for
IPersistMoniker then pass your implementation of IMoniker that
implemented BindToStorage and GetDisplayName. In BindToStorage you simply use
a TStreamAdapter and return the stream.