I have a simple XML processing code that should find the child element of a node passed in node based on the attribute value:
function GetNodeByAttributeValue(
const AParentNode: IXMLNode;
const AttributeName: string; AttributeValue: Variant): IXMLNode;
var
i: integer;
value: Variant;
begin
result := nil;
if (not Assigned(AParentNode)) or (AttributeName = '') then
exit;
for i := 0 to AParentNode.ChildrenCount-1 do
begin
result := AParentNode.Children[i];
value := result.GetAttributeValue(AttributeName, UnAssigned);
if not VarIsEmpty(value) then
exit;
end;
result := nil;
end;
Pretty simple, right? But when I try to run this, under certain circumstances it crashes with access violation. Here's what happens:
The IXML * implementation is provided by the RemObjects SDK. result.GetAttributeValuecalls uROMSXMLImpl.TROMSXMLNode.GetAttributeValuethat calls TROMSXMLNode.GetAttributeByNamewhich says
node := fNode.attributes.getNamedItem(anAttributeName);
And this is a failure because it fNode.attributesreturns nil . As I understand it, this should never be.
, for , AParentNode.ChildrenCount 3. node XML node. , .
<ParentNode>
<namespace:ChildNode name="right-name">
AParentNode.ChildrenCount 3. :
AParentNode.Children[0].name: '#text'
AParentNode.Children[1].name: 'namespace:ChildNode'
AParentNode.Children[2].name: '#text'
"#text" ? XML, . , , -, , , ?