how to send <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> as xml header in mapper
Sending an XML Declaration Header in the Mapper Snap The XML declaration <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> is an XML prolog/header, not a regular data field β so it cannot be directly mapped as a value in the Mapper Snap itself. However, here are the recommended approaches depending on your use case: --- β Recommended Approach: Use the XML Formatter Snap The XML Formatter Snap automatically prepends the XML declaration header to the output. It handles the XML prolog natively, including encoding settings. Steps: 1. Use your Mapper Snap to structure your data fields as needed. 2. Connect the Mapper output to an XML Formatter Snap. 3. In the XML Formatter, set: - Output Character Set: UTF-8 - Root element: your desired root tag (e.g., DocumentRoot) 4. The XML Formatter will automatically generate output like:
xml
<?xml version="1.0" encoding="UTF-8"?>
<DocumentRoot>
...
</DocumentRoot>
β οΈ Note: The standalone="yes" attribute in the prolog is not natively configurable in the XML Formatter. If you strictly need standalone="yes", consider the approach below.
--- β Alternative: Use the XML Generator Snap The XML Generator Snap allows you to define a custom XML template using the Edit XML button. You can manually include the full XML declaration with standalone="yes" in your template:
xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
<Field>$yourField</Field>
</Root>
Steps: 1. Place a Mapper Snap upstream to prepare your data fields. 2. Connect it to an XML Generator Snap. 3. Click Edit XML in the XML Generator and write your custom XML template including the full prolog. 4. Use Apache Velocity variable references (e.g., $fieldName) to inject dynamic values from the Mapper. --- β οΈ What NOT to Do in the Mapper - The Mapper Snap works with JSON-like document structures and does not support injecting raw XML processing instructions like <?xml ... ?> as a field value β this would be treated as a plain string, not an XML declaration. --- Summary | Approach | Supports standalone="yes" | Auto XML Header | Custom Template | |---|---|---|---| | XML Formatter Snap | β (not configurable) | β Yes | β | | XML Generator Snap | β Yes | β Yes | β Yes | For full control over the XML declaration including standalone="yes", the XML Generator Snap with a custom template is your best option.
