web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Showing xml as html on a form, but the html is generated from code.

(0) ShareShare
ReportReport
Posted on by 4,075

I have this solution that I have to move from AX2012 to D365FO.

Not in AX2012, some of the document attachments are XML files, that using code is styled into html. ( Its complicated, but that thing is not the problem )
And then the html file is shown in a form using the HtmlView AxtiveX, by setting the url of the AxtiveX = a file on the local disk system.
Simplified code would look like this.


url = this.getPublicUrl(DocuRef); // Gets an url looking like this file:///C:\Temp\tmp00001.htm
htmlView.navigate(url);

Now I have tried using the WebSiteHostControl in D365FO, but it does not seem to work on files. ( If i put the file on a webserver it shows is fine no problem)

So does anyone have a way for me to do this in D365FO?

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Rudi,

    Are you using D365FO on-prem or on the cloud? If it is on the cloud, how are you saving documents?

  • Rudi Hansen Profile Picture
    4,075 on at

    Well I am working on my devbox locally right now, but the solution is supposed to be in the cloud.

    And the documents are saved in blob storage, we are using the standard Document handling for that.

    But I was thinking that since I need to manipulate the actual file attachment, I would be faster and simpler to do that locally.

    Right now I get a tmp filepath using WinAPICS::GetTempPath(), and then use System.IO.FileStream to save the file locally.

    The filepath I get is C:\Temp\DIXF, I was counting on that to work in the cloud for the final solution.

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Rudi,

    Have you checked also HTML viewer control? If you can generate html string instead of file, you can pass HTML code to viewer control instead of using URL.

  • Rudi Hansen Profile Picture
    4,075 on at
    [quote user="Sergei Minozhenko"]

    Hi Rudi,

    Have you checked also HTML viewer control? If you can generate html string instead of file, you can pass HTML code to viewer control instead of using URL.

    [/quote]

    No have not looked at that one, but it might be the solution I will need to use thanks.

    I right now have to get the actual conversion from XML to HTML working first, and in AX2012 it uses some temporary files, and I think it would be best if I tried to change it away from using files, since it looks like D356FO is not to fond of using local files.

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Rudi,

    Have you used XSLT transformation to convert XML to HTML?

  • Rudi Hansen Profile Picture
    4,075 on at

    I am not sure I was not the one that wrote the AX2012 code, but it seems to be using System.Xml.Xls to convert it.

    Here is the original code:

    try
            {
                new InteropPermission(InteropKind::ClrInterop).assert();
        
                myXsltSettings = System.Xml.Xsl.XsltSettings::get_Default();
                myXsltSettings.set_EnableDocumentFunction(true);
        
                myResolver = new System.Xml.XmlUrlResolver();
                myResolver.set_Credentials(System.Net.CredentialCache::get_DefaultCredentials());
        
                myXslTrans = new System.Xml.Xsl.XslCompiledTransform();
                myXslTrans.Load(stylesheetFile, myXsltSettings, myResolver);
        
                outStream = new System.IO.MemoryStream();
                myXslTrans.Transform(
                myXslTrans.Transform( System.Xml.XmlReader::Create(new System.IO.StringReader(xmlData)), System.Xml.XmlWriter::Create(outStream));
        
                outStream.Seek(0, System.IO.SeekOrigin::Begin);
        
                outReader = new System.IO.StreamReader(outStream);
                ret = outReader.ReadToEnd();
        
                myXslTrans = null;
        
                CodeAccessPermission::revertAssert();
            }

    It does seem that this code reads both the stylesheet and xml data from a file, and returns a string with the transformed html.

    So I just have to figure out how to make it not use files, but perhaps strings instead.
    This is what I am looking at right now.

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Rudi,

    Yes, it's XSLT transformation.

    Load and Transform methods of XslCompiledTransform class support XmlReader and XmlWriter classes. So you just need slightly change the original implementation to use them instead of files directly and how you store stylesheet: static in resources or use document management or parameter to store the content. "Ret" variable already contains output HTML that can be passed to HTML Viewer control.

  • Rudi Hansen Profile Picture
    4,075 on at

    Ok I think I have gotten it to work, well almost there seems to be a problem with the stylesheet, it references another stylesheet that it wants to use from the disk, and it's not available.

    But that's more a problem with the stylesheet than the program.

    So just in case someone need to do XSLT transformation, here is my current code. (Sorry its still a little messy)

    resourceNode                            resourceNode    = SysResource::getResourceNode(_docuStyleTable.XsltId);
    container                               styleSheetCon   = SysResource::getResourceNodeData(resourceNode);
    str                                     styleSheetTxt   = System.Text.Encoding::UTF8.GetString(conPeek(styleSheetCon,1));
    
    System.IO.MemoryStream                  outStream;
    System.IO.StreamReader                  outReader;
    
    System.Xml.Xsl.XslCompiledTransform     xlsTransform    = new System.Xml.Xsl.XslCompiledTransform();
    
    // Remove first char from styleSheetTxt as is should not be there.
    styleSheetTxt   = subStr(styleSheetTxt,2,strLen(styleSheetTxt));
    
    // Save the stylesheet, for debugging purposes.
    this.saveString2File(styleSheetTxt,@'C:\Temp\DIXF\stylesheet.xls');
    this.saveString2File(_xmlData,     @'C:\Temp\DIXF\xmldata.xls');
    
    // Replacing the stylesheet with the original one from AX2012.
    styleSheetTxt = this.loadStringFromFile(@'C:\Temp\DIXF\stylesheet_orig.xls');
    
    System.IO.StringReader stringReader = new System.IO.StringReader(styleSheetTxt);
    System.Xml.XmlReader    xmlReader = System.Xml.XmlReader::Create(stringReader);
    
    xlsTransform.Load(xmlReader);
    xlsTransform.Transform( System.Xml.XmlReader::Create(new System.IO.StringReader(_xmlData)), System.Xml.XmlWriter::Create(outStream));
    
    outStream.Seek(0, System.IO.SeekOrigin::Begin);
    
    outReader = new System.IO.StreamReader(outStream);
    outputString = outReader.ReadToEnd();
    

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans