OCLOperators ViewModelAsXml
(Created page with "Used to create XML documents based on a viewmodel. Example; selfVM.ViewModelAsXml('ReportExportToXML', vCurrent_ReportExportView) This code will output a valid XML text for...")
 
No edit summary
Line 16: Line 16:


Converting is to a blob is necessary for downloading and will create a download link, read more here: [[BlobDownloadLink]]
Converting is to a blob is necessary for downloading and will create a download link, read more here: [[BlobDownloadLink]]
[[File:ViewModelToXMLexample.png|none|thumb|608x608px]]


=== Tagged value options ===
=== Tagged value options ===

Revision as of 10:57, 25 February 2019

This page was created by Lars.olofsson@mdriven.net on 2019-02-25. Last edited by Stephanie@mdriven.net on 2025-02-04.

Used to create XML documents based on a viewmodel.

Example;

selfVM.ViewModelAsXml('ReportExportToXML', vCurrent_ReportExportView)

This code will output a valid XML text for saving to a file/downloaded by a client;

vCurrent_ReportExportView.XML := selfVM.ViewModelAsXml('ReportExportToXML', vCurrent_ReportExportView).
replace('<root>', '<?xml version="1.0" encoding="ISO-8859-1"?>').
replace('</root>', '');

In the example the root tags are replace/removed and an XML header is added to make it a XML file (not a DOM representation).

Note the encoding in the XML (ISO-8859-1). But the string type in .Net is always Unicode in memory. So to save this correctly you need to convert it upon saving.

You can convert from Unicode to ISO-8859-1 like this (generated XML is stored in self.XML in this example);

self.XML.StringToEncodedBase64(28591).Base64ToBlob

The value 28591 is ISO 8859-1 Latin 1; Western European (ISO) taken from this table: https://docs.microsoft.com/en-us/windows/desktop/intl/code-page-identifiers

Converting is to a blob is necessary for downloading and will create a download link, read more here: BlobDownloadLink

ViewModelToXMLexample.png

Tagged value options

XmlChildnode

Single link column will be rendered as an XML element tree node

XmlAttribute

Column will be rendered as an XML Attribute