Re: Editing XML
- From: Hans-Peter Diettrich <DrDiettrich1@xxxxxxx>
- Date: Mon, 11 Jun 2007 02:43:28 +0200
Rob Kennedy wrote:
In the second step the available TWebBrowser (ShDocVw) component is very uncomfortable to use, because it's impossible to redirect navigation to some "ms-help://xyz" URL to the according HTML file.
What about the BeforeNavigate2 event? Can't you use that to cancel the original navigation and issue one of your own?
That's not possible, the event doesn't include any information about the invalid target, the URL is a standard error page in ms-help. All I can do then is a cancel of the operation.
I already verified that an invalid href target is reported to BeforeNavigate2, so that it may be possible to encode e.g. a keyword in such an URL, find the target or construct a list of possible targets, and redirect the navigation there.
So I consider to replace all <MSHelp:link ...> tags by <a href="file_to_use.htm">, and pass that modified file to the browser. Can somebody shed a light on how to update an HTML file or XMLDoc accordingly?
My first thought is to use XSLT to transform the original XML into a new XML document. Most of it would be a straight copy of the original nodes, but any nodes named <MSHelp:link> would be transformed into a corresponding <a> node instead.
This is what I'd like to try, but I'm bloody newbie with such scripts. A tutorial or other assistance would be nice...
Otherwise, load the XML document, get a list of all the MSHelp:link nodes, and rename them. I don't think you can actually rename a node through any of Delphi's interfaces, though, so what you'd have to do is create a new node, clone the original's children (with IDOMNode.cloneNode(True)), and then replace the original with the new node.
Some problems with this approach:
Changing the NodeName is impossible, as you said.
How to distinguish opening from closing tags?
How to create an closing tag, i.e. </a>?
The reported NodeName is the same for all kinds of tags, i.e. <?xml...>, <xml> and </xml> all have a NodeName of 'xml'.
Another simplified approach were a traditional find/replace in the HTML text itself. Unlike TStrings, the XMLDocument seems to use WideStrings for the stored lines, so that UTF-8 or other codepages need no special consideration.
DoDi
.
- Follow-Ups:
- Re: Editing XML
- From: Rob Kennedy
- Re: Editing XML
- References:
- Editing XML
- From: Hans-Peter Diettrich
- Re: Editing XML
- From: Rob Kennedy
- Editing XML
- Prev by Date: Re: Editing XML
- Next by Date: Re: Editing XML
- Previous by thread: Re: Editing XML
- Next by thread: Re: Editing XML
- Index(es):
Relevant Pages
|