title: NVarchar(max) to XML parse error
body: <p>Have the following configuration:
  Delphi XE7
  MS SQL Server 2008
  Connection to the SQL server with FireDAC</p>
  
  <p>I'm using stored procedures to retrieve tables with all the detail records from SQL server in XML format converted to nvarchar(max). Here is an example:</p>
  
  <pre><code>CREATE PROCEDURE uspUsers_GetAll
    @ReturnData nvarchar(max) = NULL OUTPUT
  AS
  BEGIN
    SET NOCOUNT ON;
    SET @ReturnData = CONVERT(nvarchar(max),
                  (SELECT *, (  SELECT UserID, RightType
                                FROM UserRights
                                WHERE UserRights.UserID = Users.ID
                                FOR XML RAW('UserRight'), 
                                ROOT('UserRights'), ELEMENTS, TYPE)
                  FROM Users
                  FOR XML RAW('Users'), 
                  ROOT('root') , ELEMENTS));
  END;
  </code></pre>
  
  <p>On the Delphi side I'm calling this stored procedure, load it into an XML and I'm trying to parse it in order to convert it into a local list of objects. Something like this:</p>
  
  <pre><code>procedure TUsers.LoadFromDatabase;
   var
    usersXML: String;
    xmlDoc: IXMLDocument;
    workNode: IXMLNode;
    userObj: TUser;
  begin
    Items.Clear;
  
    with dmApp.uspWork do
    begin
      Close;
      if Prepared then
        Prepared := False;
      Params.Clear;
      StoredProcName := 'uspUsers_GetAll';
      Prepare;
      ExecProc;
    end;
  
    usersXML := dmApp.uspWork.Params.ParamByName('@ReturnData').Value;
    xmlDoc := TXMLDocument.Create(nil);
    xmlDoc.LoadFromXML(usersXML);
    workNode := xmlDoc.DocumentElement;
    workNode := workNode.ChildNodes.FindNode('Users');
  
    while (workNode &lt;&gt; nil) and (workNode.NodeName = 'Users') do
    begin
      userObj := TUser.Create;
      userObj.LoadFromXMLNode(workNode);
      Items.Add(userObj);
  
      workNode := workNode.NextSibling;
    end;
  end;
  </code></pre>
  
  <p>In the above code the </p>
  
  <pre><code>workNode := workNode.ChildNodes.FindNode('Users');
  </code></pre>
  
  <p>line returns an exception somewhere deep in the Xml.XMLDoc unit. Not an error message with a specific problem I could fix. Did try with saving the xmlDoc into an xml file and it looks OK (can open it with all kind of tools like Firefox).</p>
  
  <p>The strange thing is that if I change the @ReturnData into an varchar(max) I no longer get this error.</p>
  
  <p>Any idea what I'm doing wrong?</p>