Hi @brianwhite ,
Linx 5 - ReformatXMLDemo.lsoz (9.1 KB)
Linx 6 - Linx6.zip (8.0 KB)
Using a recent example, an XML document was needed for a structure of a document. The structure was created by using Custom Types in Linx:
These are ComplexTypes which contain further ComplexTypes which creates the “nesting” of the objects:
First, we created a local instance of the main CustomType ‘Customer’, which we then populated manually.
The ComplexType ‘Document’ object is then passed into the XMLWriter function which generates and XML output, which is then written to a file using the TextFileWrite function.
The output is as the below:
The XML is well-formed, however the required structure needed is that the list of Document Info tags (DocInf) be shown in separate DocInf objects, not Item objects, and also no empty tags were allowed.
Now, it’s here where Linx provides a very nice ability, by utilizing XSLT (Extensible Stylesheet Language Transformations) you can change your XML in any way possible. For this example, we’ve set up an XSLT script (in the above thread) that removes the overarching “DocInf” tag, changed the “Item” tags to “DocInf” tags and removed all empty tags.
In the XmlWriter function, assign the above script to the ‘Transform XSLT’ property.
When you run the process, you will see that this XSLT template changes the XML to adhere to the required form (right):