Index: fcl/xml/xmlread.pp
===================================================================
RCS file: /FPC/CVS/fpc/fcl/xml/xmlread.pp,v
retrieving revision 1.16
diff -u -r1.16 xmlread.pp
--- fcl/xml/xmlread.pp	14 Mar 2005 21:10:12 -0000	1.16
+++ fcl/xml/xmlread.pp	2 May 2005 11:17:58 -0000
@@ -1297,8 +1297,10 @@
   predefined in XML: }
 
 procedure TXMLReader.ResolveEntities(RootNode: TDOMNode);
+var
+  Node, NextNode: TDOMNode;
 
-  procedure ReplaceEntityRef(EntityNode: TDOMNode; const Replacement: String);
+  procedure ReplaceEntityRef(EntityNode: TDOMNode; const Replacement: string);
   var
     PrevSibling, NextSibling: TDOMNode;
   begin
@@ -1310,6 +1312,8 @@
       RootNode.RemoveChild(EntityNode);
       if Assigned(NextSibling) and (NextSibling.NodeType = TEXT_NODE) then
       begin
+        // next sibling is to be removed, so we can't use it anymore
+        NextNode := NextSibling.NextSibling;
         TDOMCharacterData(PrevSibling).AppendData(
         TDOMCharacterData(NextSibling).Data);
         RootNode.RemoveChild(NextSibling);
@@ -1323,13 +1327,11 @@
         RootNode.ReplaceChild(Doc.CreateTextNode(Replacement), EntityNode);
   end;
 
-var
-  Node, NextSibling: TDOMNode;
 begin
   Node := RootNode.FirstChild;
   while Assigned(Node) do
   begin
-    NextSibling := Node.NextSibling;
+    NextNode := Node.NextSibling;
     if Node.NodeType = ENTITY_REFERENCE_NODE then
       if Node.NodeName = 'amp' then
         ReplaceEntityRef(Node, '&')
@@ -1341,7 +1343,7 @@
         ReplaceEntityRef(Node, '<')
       else if Node.NodeName = 'quot' then
         ReplaceEntityRef(Node, '"');
-    Node := NextSibling;
+    Node := NextNode;
   end;
 end;
 
