-1

I'm trying to understand using OmniXML in our application which is going to be written in Delphi 10 Seatlle. I've scavenged the internet but all I can find are samples which obviously use another version of Delphi and/or another version of OmniXML as the statements they are using are not accepted anymore

like

 var doc: IXMLDocument;
 doc := CreateXMLDoc;
 doc.selectSingleNode(....);
 doc.SelectNodes(...);

I'm especially interested in using Selectnodes() with namespaces (where in the MSXML implementation the "SelectionNamespaces" property had to be set).

Can anyone provide me with or point me to a working example of OmnniXML in delphi 10 Seattle?

Bascy
  • 2,017
  • 1
  • 21
  • 46
  • It's quite hard to get past all the spelling mistakes here. It's also quite hard to believe that OmniXML has changed so much that all the historical examples are no longer valid. What does "nog accepted anymore" mean? Was there some actual code and an error message? It would be better if you would post a complete program that failed to compile (or failed to run if the errors are runtime errors) and ask for help with it. Asking for an example is off topic here: http://stackoverflow.com/help/on-topic. – David Heffernan Mar 08 '16 at 15:43
  • the above code does not compile, non of the 3 statements are valid ;-) Problem with most samples i found was that there was no specification of the uses clause, which makes it almost impossible to recreate for a xml beginner as myself, drowning in XMLDoc, XMLDOm, Omnixmldom, XMLintf etc etc etc – Bascy Mar 08 '16 at 15:56
  • OmniXML looks like it is dead in any case. Are you sure it's a good choice. – David Heffernan Mar 08 '16 at 16:00
  • The OmniXML interfaces have not changed in quite some time, so it's much more likely that you're just missing a unit in the uses clause. As you've failed to post a MCVE that shows what you're actually trying to do, it's impossible to say for sure. I use OmniXML in some legacy projects that have been updated to Seattle and they all work fine. – Ken White Mar 08 '16 at 16:57
  • @davidhefferman omnixml is part of Delphi 10 and advertised as the multiplatform alternative in the embarcadero documentation. I don't expect it to be dead – Bascy Mar 08 '16 at 20:30
  • @kenwhite I have a working example. Will post it tomorrow – Bascy Mar 08 '16 at 20:31
  • 1
    @Bascy As a standalone project OmniXML seems moribund. I wasn't aware that it had been absorbed by Emba for x-plat purposes, but it makes good sense. I think that the point is that you use the standard Emba XML RTL library, but with omnixml as the DOM vendor. So you don't want to use OmniXML examples. You want to use XMLDoc examples. Another way to think of this is that you aren't using OmniXML as such, but it's just the backend, the vendor DOM. – David Heffernan Mar 08 '16 at 21:38

1 Answers1

0

Wel I got it running with the following code. Still keeps me wondering how to use Namespaces in XPATH searches but I will post another question on that.

program Project1;
{$APPTYPE CONSOLE}
{$R *.res}

uses
  System.SysUtils,
  XML.XMLDom,
  XML.XMLDoc,
  XML.omnixmldom,
  XML.XMLIntf
  ;

const
  cXML = '<?xml version="1.0"?>' +
         '<catalog xmlns:xs12=''http://www.w3.org/2001/XMLSchema-instance''>' +
         '   <xs12:book id="bk101">' +
         '     <xs12:author>Gambardella, Matthew</xs12:author>' +
         '      <xs12:title>XML Developers Guide</xs12:title>' +
         '    <xs12:genre>Computer</xs12:genre>' +
         '    <xs12:price>44.95</xs12:price>' +
         '    <xs12:publish_date>2000-10-01</xs12:publish_date>' +
         '    <xs12:description>An in-depth look at creating applications with  XML.</xs12:description>' +
         '</xs12:book>'
          + '</catalog>'
         ;
var
  doc: IXMLDocument;
  list: IDOMNodeList;
  lSelectNode: IdomNodeSelect;
begin

  DefaultDOMVendor := sOmniXmlVendor;
  try
    try
      doc := LoadXMLData(cXML);

      doc.DocumentElement.DeclareNamespace('a', 'http://www.w3.org/2001/XMLSchema-instance');

      if supports(doc.DOMDocument, IDomNodeSelect, lSelectNode) then
      begin
        list := lSelectNode.selectNodes('a:book');
        Writeln(Format( '%d nodes', [List.length]));
      end;

    except
      on E: Exception do
        Writeln(E.ClassName, ': ', E.Message);
    end;
  finally
  end;
end.
Bascy
  • 2,017
  • 1
  • 21
  • 46