cancel
Showing results for 
Search instead for 
Did you mean: 

How to Convert .txt data in xml in sap cpi

former_member538292
Participant
0 Kudos

Hi All,

Hope all are doing well...

I have a requirement is,I posting a .txt file from postman to cpi I need convert into xml.

exmaple:

Order

123456789,

236598747,

212365849

this is the data in Order.txt file now i am posting to cpi now i need to convert like below,

<Orders>

<Order>123456789</Order>

<Order>236598747</Order>

<Order>212365849</Order>

</Orders>

I used standard converter csv to xml is not working.

Thanks,

Kumar

View Entire Topic
RobertQ
Explorer
0 Kudos

Hello Kumar,

the standard converter is creating a structure, that has one more level. If that is fine for your requirement, you can use it in the following way. If you need the target structure as defined by you, you can do a mapping to achive that.

  • Define your XSD for the target structure:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<xsd:element name="Orders">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element name="Order" minOccurs="1" maxOccurs="unbounded">
					<xsd:complexType>
						<xsd:sequence>
							<xsd:element name="ID" type="xsd:string"/>
						</xsd:sequence>
					</xsd:complexType>
				</xsd:element>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
</xsd:schema>
  • Import it as the schema into CPI:

  • Input file (The seperator is irelevant if you only have one field/column):
Order
123456789
236598747
212365849
  • Output (I intended the output for better readability):
<?xml version='1.0' encoding='UTF-8'?>
<Orders>
	<Order>
		<ID>123456789</ID>
	</Order>
	<Order>
		<ID>236598747</ID>
	</Order>
	<Order>
		<ID>212365849</ID>
	</Order>
</Orders>

Best regards

Robert

former_member538292
Participant
0 Kudos

Hi Robert,

Thank for making very clear ...

I tried what you are suggested but I am getting below payload.when i simulating it is giving same like your out but when post the same file from postman it giving like below

<?xml version='1.0' encoding='UTF-8'?>
<Orders>
<Order>
<ID>Content-Disposition: form-data; name="Order"; filename="Order.txt"</ID>
</Order>
<Order>
<ID>Content-Type: text/plain</ID>
</Order>
<Order>
<ID>Order</ID>
</Order>
<Order>
<ID>00000123456789</ID>
</Order>
<Order>
<ID>00000123456785</ID>
</Order>
<Order>
<ID>00000123456788</ID>
</Order>
<Order>
<ID>----------------------------681027471091768597048543--</ID>
</Order>
</Orders>

Thanks in advance,

Kumar

RobertQ
Explorer

Helo Kumar,

please chck your settings in postman. You are sending the data as "form-data". Please send them as "raw" instead.

Best regards

Robert

former_member538292
Participant
0 Kudos

Hi Robert,

yes it is working

Thanks,

Kumar