Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Count Nodes

126 views
Skip to first unread message

Alfonso Sanz

unread,
Feb 3, 2004, 5:35:55 AM2/3/04
to
Hallo,

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

Jeff Rafter

unread,
Feb 3, 2004, 11:22:03 AM2/3/04
to
> In XPATH I could use count("//INPUTNODE"). How can I call this
> xpath-fuction from Delphi? With Selectnodes it does not work.

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


Michael Green

unread,
May 19, 2004, 9:38:14 AM5/19/04
to
I have exactly the same problem. The code is:

////////////////////////////////////////////////////////////////////////////
////
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


Jeff Rafter

unread,
May 19, 2004, 12:13:16 PM5/19/04
to
Executing XPath functions and attempting to get these as a result from
selectSingleNode is not allowed as far as I know. It should be-- or rather
would be nice. Unfortunately selectNodes and selectSingleNode return an
IXMLNode and IXMLNodeList respectively. So you have to work in that context.
Luckily count is easy : ) Something like this would do it:

list:= myNode.selectNodes("*");
count:= list.length;

Other functions though (like string functions) are not as fun.

Cheers,
Jeff Rafter


Michael Green

unread,
May 19, 2004, 1:34:10 PM5/19/04
to
I feared as much. Thanks anyways.


0 new messages