Usecase:
While building an integration in OIC, you may come across a requirement where the target SOAP or XML structure contains a field of type <any>
(or xs:anyType
). These fields are placeholders meant to accept any valid XML content, but OIC’s Mapper UI doesn’t allow direct drag-and-drop mappings for such fields.
This can be confusing and frustrating, especially when you're trying to pass a dynamic XML or construct a custom payload. Here's how to deal with this in a clean and simple way.
Solution Steps
Step 1: Identify the <any>
Field
In your target structure, locate the field labeled as <any>
or marked with type xs:anyType
.
Step 2: Switch to XSLT View
In the Mapper canvas:
- Click on the
</>
icon (usually found in the upper right of the mapping panel).
- This will open the raw XSLT mapping code.
Step 3: Manually Add a Custom XML Payload
Here, insert a valid XML snippet that the target system expects. Example:
<any>
<ns1:CustomData xmlns:ns1="http://example.com/schema">
<ns1:DeviceId>{/ns0:TriggerService/Request/GetMeterReadings/EndDevice}</ns1:DeviceId>
<ns1:ReadingType>{/ns0:TriggerService/Request/GetMeterReadings/ReadingType}</ns1:ReadingType>
</ns1:CustomData>
</any>
Replace /ns0:TriggerService/...
with actual source path expressions from your input.
Step 4: Validate and Save
- Ensure the XML syntax is correct.
- Click Validate in the mapper toolbar.
- Save your changes and return to the visual canvas.
Optional: Use JavaScript or Stage File for Complex Data
If the XML is very dynamic:
- Use a JavaScript action to build the payload.
- Or read it from a stage file and assign it as a single string/XML object.
Used code: we have used local-namespace() function and apply template
<xsl:param name="tracking_var_3" xml:id="id_21"/>
<xsl:template match="/" xml:id="id_11">
<nstrgmpr:OutboundSOAPRequestDocument xml:id="id_12">
<nstrgmpr:Body>
<ns2:RequestMessage>
<ns2:Header>
<ns2:Verb>
<xsl:value-of select="//*[local-name()='RequestMessage']//*[local-name()='Header']/*[local-name()='Verb']/text()"/>
</ns2:Verb>
<ns2:Noun>
<xsl:value-of select="//*[local-name()='RequestMessage']//*[local-name()='Header']/*[local-name()='Noun']/text()"/>
</ns2:Noun>
<ns2:Timestamp>
<xsl:value-of select="//*[local-name()='RequestMessage']//*[local-name()='Header']/*[local-name()='Timestamp']/text()"/>
</ns2:Timestamp>
<ns2:Source>
<xsl:value-of select="//*[local-name()='RequestMessage']//*[local-name()='Header']/*[local-name()='Source']/text()"/>
</ns2:Source>
<ns2:ReplyAddress>
<xsl:value-of select="//*[local-name()='RequestMessage']//*[local-name()='Header']/*[local-name()='ReplyAddress']/text()"/>
</ns2:ReplyAddress>
<ns2:MessageID>
<xsl:value-of select="//*[local-name()='RequestMessage']//*[local-name()='Header']/*[local-name()='MessageID']/text()"/>
</ns2:MessageID>
<ns2:CorrelationID>
<xsl:value-of select="//*[local-name()='RequestMessage']//*[local-name()='Header']/*[local-name()='CorrelationID']/text()"/>
</ns2:CorrelationID>
</ns2:Header>
<ns2:Request>
<xsl:apply-templates select="//*[local-name()='RequestMessage']"/>
</ns2:Request>
</ns2:RequestMessage>
</nstrgmpr:Body>
</nstrgmpr:OutboundSOAPRequestDocument>
</xsl:template>
<xsl:template match="//*[local-name()='RequestMessage']">
<nsd10:GetMeterReadings>
<xsl:for-each select="*[local-name()='Request']/*[local-name()='GetMeterReadings']/*[local-name()='EndDeviceAsset']">
<nsd10:EndDevice>
<nsd10:Names>
<nsd10:name>
<xsl:value-of select="*[local-name()='mRID']/text()"/>
</nsd10:name>
</nsd10:Names>
</nsd10:EndDevice>
</xsl:for-each>
<xsl:for-each select="*[local-name()='Request']/*[local-name()='GetMeterReadings']/*[local-name()='ReadingType']">
<nsd10:ReadingType>
<xsl:value-of select="*[local-name()='name']/text()"/>
</nsd10:ReadingType>
</xsl:for-each>
</nsd10:GetMeterReadings>
</xsl:template>
</xsl:stylesheet>
Screenshot:
Conclusion
Although <any>
fields are not directly mappable in OIC’s graphical interface, you can still pass data to them using XSLT view and inserting well-formed XML manually. This gives you flexibility while still adhering to schema requirements.
No comments:
Post a Comment