簡體   English   中英

在 Delphi 10 Seattle 中使用 OmniXML 實現

[英]Using OmniXML implementation in Delphi 10 Seattle

我試圖了解在我們將用 Delphi 10 Seatlle 編寫的應用程序中使用 OmniXML。 我已經搜索了互聯網,但我能找到的只是顯然使用另一個版本的 Delphi 和/或另一個版本的 OmniXML 的示例,因為它們使用的語句不再被接受

喜歡

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

我對將 Selectnodes() 與命名空間一起使用特別感興趣(在 MSXML 實現中,必須設置“SelectionNamespaces”屬性)。

任何人都可以向我提供或指向我在 delphi 10 Seattle 中的 OmniXML 工作示例嗎?

好吧,我使用以下代碼運行它。 仍然讓我想知道如何在 XPATH 搜索中使用命名空間,但我會發布另一個問題。

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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM