Read file inside BPEL using Xpath function
2. Using java embedding
We generally use file adapter to read, write or poll files from different file locations. But, in case if don't want to create a file adapter and don't want to go for java embedding. We can make use of BPEL xpath extension functions. In this article, we will discuss about reading a file using xpath function ora:readFile().
Xpath expression:
xmlns:ora = http://schemas.oracle.com/xpath/extension
'fileName': Refers to absolute path of file along with extension. This is mandatory field.
'schemaLocation' : Refers to location of nxsd schema for the file to be read. This is an optional field. If you don't provide the schema location, then data from the file will be read and converted to base64 encoded string
'rootElement' : Refers to root element in nxsd schema. This is optional field but required if we provide schema location.
Example:
Sample CSV file with absolute file path: C:\Users\test\SOA\test1.csv
1,t1,t2,t3
2,s1,s2,s3
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd" xmlns:tns="http://TargetNamespace.com/ServiceName" targetNamespace="http://TargetNamespace.com/ServiceName" elementFormDefault="qualified" attributeFormDefault="unqualified" nxsd:version="NXSD" nxsd:stream="chars" nxsd:encoding="UTF-8" nxsd:hasHeader="true" nxsd:headerLines="1" nxsd:headerLinesTerminatedBy="${eol}">
<xsd:element name="Root-Element">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="row" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="S.No" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="""/>
<xsd:element name="Field1" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="""/>
<xsd:element name="Field2" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="""/>
<xsd:element name="Field3" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy="""/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<row>
<S.No>1</S.No>
<Field1>t1</Field1>
<Field2>t2</Field2>
<Field3>t3</Field3>
</row>
<row>
<S.No>2</S.No>
<Field1>s1</Field1>
<Field2>s2</Field2>
<Field3>s3</Field3>
</row>
This comment has been removed by the author.
ReplyDelete