Delphi :office:spreadsheet'-我不知道这在规范方面是否正确,但如果是,那么它就是一个重要的oversite…我可能只是删除默认名称空间,但是可能会有带有显式前缀标记的文件。。。。我会核对你的解释。如果它是正确的,那么MSXML XPath似乎不
Delphi :office:spreadsheet'-我不知道这在规范方面是否正确,但如果是,那么它就是一个重要的oversite…我可能只是删除默认名称空间,但是可能会有带有显式前缀标记的文件。。。。我会核对你的解释。如果它是正确的,那么MSXML XPath似乎不,delphi,xpath,delphi-xe2,msxml,txmldocument,Delphi,Xpath,Delphi Xe2,Msxml,Txmldocument,:office:spreadsheet'-我不知道这在规范方面是否正确,但如果是,那么它就是一个重要的oversite…我可能只是删除默认名称空间,但是可能会有带有显式前缀标记的文件。。。。我会核对你的解释。如果它是正确的,那么MSXML XPath似乎不适合这个…@Arioch'您根本不需要更改XML文件。您只需要告诉MSXML为默认名称空间使用特定前缀,并在XPath查询中使用该名称空间。我在回答中给出的两个更改是我对代码所做的唯一两个更改。在工作中,我们制作了帮助函数来添加这些前缀,使生活
:office:spreadsheet'-我不知道这在规范方面是否正确,但如果是,那么它就是一个重要的oversite…我可能只是删除默认名称空间,但是可能会有带有显式前缀标记的文件。。。。我会核对你的解释。如果它是正确的,那么MSXML XPath似乎不适合这个…@Arioch'您根本不需要更改XML文件。您只需要告诉MSXML为默认名称空间使用特定前缀,并在XPath查询中使用该名称空间。我在回答中给出的两个更改是我对代码所做的唯一两个更改。在工作中,我们制作了帮助函数来添加这些前缀,使生活变得更简单,我将把这个函数添加到我的答案中。@Arioch'the Nothing使它成为默认值,这就是为什么你需要在任何地方指定它,否则你就不会指定它(因为它是默认值)。
<?xml version="1.0" encoding="UTF-8"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
....
<Worksheet ss:Name="Карточка">
....
</Worksheet>
<Worksheet ss:Name="Баланс">
...
...
...
</Worksheet>
</Workbook>
procedure DoParseSheets( FileName: string );
var
rd: IXMLDocument;
ns: IDOMNodeList;
n: IDOMNode;
sel: IDOMNodeSelect;
ms: IXMLDOMDocument2;
ms1: IXMLDOMDocument;
i: integer;
s: string;
begin
rd := TXMLDocument.Create(nil);
rd.LoadFromFile( FileName );
if Supports(rd.DocumentElement.DOMNode,
IDOMNodeSelect, sel) then
begin
ms1 := (rd.DOMDocument as TMSDOMDocument).MSDocument;
if Supports( ms1, IXMLDOMDocument2, ms) then begin
ms.setProperty('SelectionNamespaces',
'xmlns="urn:schemas-microsoft-com:office:spreadsheet" '+
'xmlns:o="urn:schemas-microsoft-com:office:office" '+
'xmlns:x="urn:schemas-microsoft-com:office:excel" '+
'xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"');
ms.setProperty('SelectionLanguage', 'XPath');
end;
// ns := sel.selectNodes('/Workbook/Worksheet/@ss:Name/text()');
// ns := sel.selectNodes('/Workbook/Worksheet/@Name/text()');
ns := sel.selectNodes('/Workbook/Worksheet/@ss:Name');
// ns := sel.selectNodes('/Workbook/Worksheet/@Name');
// ns := sel.selectNodes('/Workbook/Worksheet');
for i := 0 to ns.length - 1 do
begin
n := ns.item[i];
s := n.nodeValue;
ShowMessage(s);
end;
end;
end;
ms.setProperty('SelectionLanguage', 'XPath');
ms.setProperty('SelectionNamespaces',
'xmlns:AnyPrefix="urn:schemas-microsoft-com:office:spreadsheet"');
ns := sel.selectNodes(
'/AnyPrefix:Workbook/AnyPrefix:Worksheet/@AnyPrefix:Name' );
ms.setProperty('SelectionNamespaces',
'xmlns:d="urn:schemas-microsoft-com:office:spreadsheet" '+
'xmlns:o="urn:schemas-microsoft-com:office:office" '+
'xmlns:x="urn:schemas-microsoft-com:office:excel" '+
'xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"');
ns := sel.selectNodes('/d:Workbook/d:Worksheet/@ss:Name');