function docXML = getDocumentationXML(topic)
%getDocumentationXML Extracts the documentation content from the live code file to be displayed in doc.
%   getDocumentationXML(topic) topic is the file path of the live code file. methodName is the
%   optional argument specifying a method page to be displayed

%   Copyright 2017-2018 The MathWorks, Inc.

   % When calling doc on a method, that gets passed in the form of "className/methodName"
   % We'll split up the string to check for any extra elements
   topicParts = strsplit(topic, '/');
   topic = topicParts{1};
   
   filePath = which(topic, '-all');
   isMlxFile = false;
   if(~isempty(filePath))
    filePath = char(filePath{1});
    isMlxFile = com.mathworks.services.mlx.MlxFileUtils.isMlxFile(filePath);
   end
   if ~isMlxFile
       docXML = '';
       return;
   end
   opcPackage  = com.mathworks.services.mlx.MlxFileUtils.read(java.io.File(filePath));
   docXML  = com.mathworks.services.mlx.OpcUtils.getDocumentationFromOpcPackage(opcPackage);
   docXML = com.mathworks.services.mlx.documentation.DocumentationParser.getReleaseCompatibleXML(docXML);

   % If a methodName was specified, extract out the relevant doc info. If "methodName" is not found,
   % then the original "docXML" will be returned
   if length(topicParts) > 1
       methodName = topicParts{2};
       docXML = com.mathworks.services.mlx.documentation.DocumentationParser.getMethodDocXML(docXML, methodName);
   end
end