Re: Editing XML



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
.



Relevant Pages

  • RE: Is there a way to run a procedure before the paste command?
    ... Private Sub Worksheet_SelectionChange(ByVal Target As Range) ... "Carl" wrote: ... Cancel is only meaingful in Events that have a name including the word ...
    (microsoft.public.excel.programming)
  • Re: pop-up calculator
    ... Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) ... A better solution is to make the Calculator window a child of the main Excel window. ...
    (microsoft.public.excel.programming)
  • Re: Checkbox in Excel-Zelle einfügen
    ... mir fiel aber nichts besseres ein da ich den Sinn des Cancel-Parameter ... Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As ...
    (microsoft.public.de.excel)
  • RE: Double-Click to Change Interoir Color
    ... (ByVal Target As Range, Cancel As Boolean) ... Const myRange As String = ... Cancel = True 'preserve double-click edit for cells not in MyRange ... IF D12 is double-clicked the interior color is changed to gray. ...
    (microsoft.public.excel.programming)