The following code throws an "InvalidPointer" exception everytime I try to access the document's root with XMLDocument.DocumentElement;
.
begin
XMLDocument := TXMLDocument.Create(nil); // nil since we don't need an owner
AStream := TStream.Create; // stream for output as string
XMLDocument.loadFromXML(xml);// load string
if NOT (XMLDocument.IsEmptyDoc) then
begin
XMLDocument.Active := true; // actually automatically done by 'loadFromXML'
// get document root
HeadNode := XMLDocument.DocumentElement;
// add <id>-element, set ID as text
idNode := HeadNode.AddChild(XML_ID_PLAIN);
idNode.Text := id;
// ...
end;
end;
The string "xml" passed to loadFromXML(string)
is valid XML, but the XMLDocument's properties "XML" and "DOMDocument" are always nil
, even though neither the object itself nor its "IsEmptyDoc" properties are. Delphi Version is still 2007.
Has anyone an idea what causes this? Thanks in advance.