I want to count the total number of Nodes with the name "INPUTNODE"
at the moment I do it with xmlOverfl.selectNodes('//INPUTNODE').length.
In XPATH I could use count("//INPUTNODE"). How can I call this
xpath-fuction from Delphi? With Selectnodes it does not work.
Regards
Alfonso
No, XPath functions are not available as such-- it would be nice if they
were. The code for selectNodes looked right-- can you give a more complete
example of the problem?
All the best,
Jeff Rafter
////////////////////////////////////////////////////////////////////////////
////
function TTKFlatToXML.GetXPathQueryValue(AContext: IXMLDOMNode;
AQuery: string): string;
////////////////////////////////////////////////////////////////////////////
////
{Run an XPath query in the context of the attribute for which it is
defined.}
var
Answer: IXMLDOMNode;
begin
if (trim(AQuery) <> '') then
begin
try
Answer := AContext.selectSingleNode(AQuery); <--
exception here.
except
on E: Exception do
begin
raise EXPath.Create('TTKFlatToXMLImpEx.GetXPathQueryValue:
processing query "' +
AQuery + '" produced the exception "' + E.Message + '"');
end;
...
end; //GetXPathQueryValue
I pass in an IXMLDOMAttribute as AContext and "count(*)" (without the
quotes) as AQuery. The exception message is 'Unknown
method.'#$D#$A#$A'-->count(*<--)'. Other queries, such as "." and "..",
return the expected result.
I've tried myriad variations on "count(*)" and none of them work. Neither
do they work if I pass an IXMLDOMElement as AContext.
This is all part of a utility that translates our internal XML to flat files
for interfacing with external systems. I'd like to use the count() function
to populate header/trailer records. If anyone can think of an alternative
I'd be grateful.
Michael Green
Consilium Technologies
N. Ireland
list:= myNode.selectNodes("*");
count:= list.length;
Other functions though (like string functions) are not as fun.
Cheers,
Jeff Rafter