Re: Editing XML



Hans-Peter Diettrich wrote:
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...

OK. Um... heh. I was afraid you might ask about that. I'll get back to you later.

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>?

Don't deal with tags. Deal with nodes. Let the nodes determine their tags during serialization (writing the DOM tree to a file).

The reported NodeName is the same for all kinds of tags, i.e. <?xml...>, <xml> and </xml> all have a NodeName of 'xml'.

But they should have different types. The former should be denoted as a processing instruction, not an element, for instance. The latter two are really part of a single node.

I'll see whether I can make an example for this way, too. I've only done XML stuff in Delphi once before.

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.

Right. XML always uses Unicode internally. UTF-8 and other code pages are simply used for serialization.

--
Rob
.



Relevant Pages

  • RE: FSMT
    ... I already do the Change of target Share Name. ... I have written "(i do this with an external tools that parse the xml)" then ... > Q. In the File Server Migration Wizard, why is the source file server name ... > 2.Close the File Server Migration Wizard. ...
    (microsoft.public.windows.server.migration)
  • Re: MS Word how to connect :)
    ... Sounds like you'd have to use ActiveX Automation to control Word. ... Is your application target more than one machine on which different versions ... This XML format is publicly documented by MSFT. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Target Namespace in schemas.
    ... When adhering the XML spec and guidance, ... specific XML schema then... ... > I have a problem relating target namespaces in the schemas. ... > If I set a target namespace in the schema the resulting xml will look ...
    (microsoft.public.biztalk.general)
  • Re: Which Linux for a beginning desktop?
    ... MSIE has not been a target for active development in some time. ... don't use xml or xhtml, nor do 99.999% of sites on the Web, so I don't ...
    (comp.os.linux)