Wel我用下面的代碼運行它。仍然讓我想知道如何在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.
這裏很難弄清所有的拼寫錯誤。也很難相信OmniXML發生了很大的變化,所有的歷史示例都不再有效。 「nog接受了什麼」是什麼意思?是否有一些實際的代碼和錯誤信息?如果您發佈完整的程序無法編譯(或者如果錯誤是運行時錯誤,則運行失敗)並尋求幫助。請求一個例子在這裏脫離主題:http://stackoverflow.com/help/on-topic。 –
上面的代碼不能編譯,3個語句中沒有一個是有效的;-)我發現大多數樣本的問題是沒有使用子句的規範,這使得幾乎不可能爲xml初學者重新創建自己,溺水在XMLDoc,XMLDOm,Omnixmldom,XMLintf等等等等等等等等 – Bascy
OmniXML看起來好像在任何情況下都是死的。你確定這是一個不錯的選擇。 –