Selecting Nodes Not Equal to a Value

(One for the memory banks)

procedure DoNodes(nodes: IXMLDOMNodeList; 
  nodeCallback: TNodeEvent);
var
  i: Integer;
begin
  if Assigned(nodes) then
    for i := 0 to nodes.length - 1 do
      nodeCallback(nodes.item[i]);
end;

procedure DoPropertyNodesNotEqualToValue(
  fromNode: IXMLDOMNode; propertyName: WideString;
  excludeValue: WideString; nodeCallback: TNodeEvent);
var
  xPath: WideString;
  nodes: IXMLDOMNodeList;
begin
  if Assigned(fromNode) then
  begin
    // Build the xpath expression assuming we want to
    // match a text-type value.
    xPath := Format('./property[@name="%s"][.!="%s"]',
      [propertyName, value]);
    // Extract the nodes that don't have this value.
    nodes := fromNode.selectNodes(xPath);
    // Process the nodes to the callback routine.
    DoNodes(nodes, nodeCallback);
  end;
end;

// Overloaded version with value as Integer.
procedure DoPropertyNodesNotEqualToValue(
  fromNode: IXMLDOMNode; propertyName: WideString;
  excludeValue: Integer; nodeCallback: TNodeEvent);
var
  xPath: WideString;
  nodes: IXMLDOMNodeList;
begin
  if Assigned(fromNode) then
  begin
    // Build the xpath expression assuming we want to
    // match a text-type value.
    xPath := Format('./property[@name="%s"][.!=%d]',
      [propertyName, value]);
    // Extract the nodes that don't have this value.
    nodes := fromNode.selectNodes(xPath);
    // Process the nodes to the callback routine.
    DoNodes(nodes, nodeCallback);
  end;
end;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: