However, other sources do. So if you want to use for example the header data of an XML IDoc DC40 fragment to call a web service, you need to transform the string based date value CREDAT and the string based time value CRETIM to the more appropriate xsd:dateTime.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:sap-com:document:sap:idoc"
xmlns="urn:sap-com:document:sap:idoc"
elementFormDefault="qualified">
<xsd:element name="IDOCTYPEOFYOURCHOICE">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="IDOC" maxOccurs="unbounded" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="EDI_DC40">
<xsd:complexType>
<xsd:sequence>
...
<xsd:element name="CREDAT" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="8"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="CRETIM" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="6"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
...
</xsd:sequence>
...
</xsd:complexType>
</xsd:element>
...
</xsd:sequence>
...
</xsd:complexType>
</xsd:element>
</xsd:sequence>
...
</xsd:complexType>
</xsd:element>
</xsd:schema>
You can achieve this by assigning string data in the correct pattern to an xsd:dateTime element. This is possible since xsd:dateTime is accepting string inputs. However, the pattern of xsd:dateTime has to be respected. For our example, it is enough to target the pattern "yyyy-mm-ddThh:mm:ss" without the optional milliseconds and time zone parameters. Check out detailed information in XML Schema Definition Part 2 Datatypes.
The little POC for this is based on a synchronous BPEL process waiting for input data similar to XML IDoc data. An XSL Transformation is used to transform the string-based input data to xsd:dateTime data. Additionally, the XSL engine will add a generated xsd:dateTime value of the runtime environment. The following figure shows the BPEL process.
BPEL process GenerateTime |
SCA composite overview of the POC |
XML Schema definition of the POC |
The following screenshot is taken from the XSLT editor in JDeveloper with SOA extension.
XSL Transformation is XSLT editor |
<xsl:template match="/">
<ns1:response>
<ns1:customDateTime>
<xsl:value-of select="concat(
substring(/ns1:request/ns1:date,1.0,4.0),'-',
substring(/ns1:request/ns1:date,5.0,2.0),'-',
substring(/ns1:request/ns1:date,7.0,2.0),'T',
substring(/ns1:request/ns1:time,1.0,2.0),':',
substring(/ns1:request/ns1:time,3.0,2.0),':',
substring(/ns1:request/ns1:time,5.0,2.0))"/>
</ns1:customDateTime>
<ns1:generatedDateTime>
<xsl:value-of select="xp20:current-dateTime()"/>
</ns1:generatedDateTime>
</ns1:response>
</xsl:template>
Now let's test the process (and XSL transformation) from Enterprise Manager, providing some sample data ...
Input data for testing |
Output data of the test |
Here you can download the complete POC.
No comments:
Post a Comment