2
下面的代碼每次嘗試訪問文檔的根目錄時都會引發「InvalidPointer」異常,其格式爲XMLDocument.DocumentElement;
。Delphi:嘗試訪問XMLDocument時出現EInvalidPointer
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;
字符串「XML」傳遞給loadFromXML(string)
是有效的XML,但XmlDocument的屬性「XML」和「DOM文檔」總是nil
,儘管無論是物體本身還是其「IsEmptyDoc」屬性。德爾福版本仍然是2007.
有沒有人有一個想法是什麼原因造成的?提前致謝。
我有一個預感,如果你告訴我們什麼類型的XMLDocument變量,答案就會變得明顯。 –