No edit summary |
No edit summary |
||
Line 7: | Line 7: | ||
replace('<root>', '<?xml version="1.0" encoding="ISO-8859-1"?>'). | replace('<root>', '<?xml version="1.0" encoding="ISO-8859-1"?>'). | ||
replace('</root>', <nowiki>''</nowiki>); | replace('</root>', <nowiki>''</nowiki>); | ||
In the example the root elements are | In the example the root elements are replaced/removed and an XML header is added to make it a XML file (not a DOM representation). | ||
Note the encoding in the XML header says ISO-8859-1. But the '''string''' type in .Net is always Unicode in memory. To save this correctly you need to convert it upon saving. | Note the encoding in the XML header says ISO-8859-1. But the '''string''' type in .Net is always Unicode in memory. To save this correctly you need to convert it upon saving. | ||
Line 21: | Line 21: | ||
==== XmlChildnode ==== | ==== XmlChildnode ==== | ||
Default for single associations in the viewmodel is to add more elements to the parent with the style <classname>.<attribute name>. If you use XmlChildNode = true, single associations will be rendered as an XML element instead. | Default for single associations in the viewmodel is to add more elements to the parent with the style <classname>.<attribute name>. If you use XmlChildNode = true, single associations will be rendered as an XML child element instead. | ||
Default for many associations in the viewmodel is to add a child element and then one child element under that for each object in the association. If you use XmlChildNode = false, the first child element will be omitted. | Default for many associations in the viewmodel is to add a child element and then one child element under that for each object in the association. If you use XmlChildNode = false, the first child element will be omitted. |
Revision as of 11:23, 25 February 2019
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 elements are replaced/removed and an XML header is added to make it a XML file (not a DOM representation).
Note the encoding in the XML header says ISO-8859-1. But the string type in .Net is always Unicode in memory. 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 it to a blob is necessary for downloading and will create a download link, read more here: BlobDownloadLink
Tagged value options
XmlChildnode
Default for single associations in the viewmodel is to add more elements to the parent with the style <classname>.<attribute name>. If you use XmlChildNode = true, single associations will be rendered as an XML child element instead.
Default for many associations in the viewmodel is to add a child element and then one child element under that for each object in the association. If you use XmlChildNode = false, the first child element will be omitted.
XmlAttribute
Default for attributes in the viewmodel is to be rendered as a XML element. If you use XmlAttribute = false, columns will be rendered as an XML attribute instead.
See also
OCLOperators StringToBase64 for UTF8 encoding.
OCLOperators XsltTransformXml for transforming the created XML to another format.