Expand my Community achievements bar.

Convert Text file to XML?

Avatar

Former Community Member

Hi there, I have a newbie question that I am hoping someone can help me with.

I have to create a process in ES2 that leverages a watched folder as the end point.  The incoming data file is TXT file that has the data formatted like the following:

FirstName=John

LastName=Doe

PhoneNumber=555-555-5555

EmailAddress=jdoe@email.com

The process needs to first save the data to a seperate DB table outside of LC and then send an email notification to the contact name.  There is no PDF form or User Tasks required in these operations. 

My initial question is what to do with the format of the incoming data file.  I am assuming it should be first converted to XML before the LC process consumes it.  What would be the best approach to go about doing this? 

Many thanks

NC_12

2 Replies

Avatar

Level 10

Use Properties class to read values from the file and then create an XML document using DOM Parser.

After conversion, you can send the XML through email.

Nith

Avatar

Former Community Member

Best approach would be to make the input file of xml extension and provide values in different xml tags ,so your input would look as:-

<FirstName>John</FirstName>

<LastName>Doe</LastName>

<PhoneNumber>555-555-5555</PhoneNumber>

<EmailAddress>jdoe@email.com</EmailAddress>

In your ES2 process, make one input variable of type document for taking this xml file. Now once this document (xml) type file comes in ur process. then use SetValue component to convert the content type of this document to "application/xml".

e.g. Input variable name is "inXMLDoc" of type document which would be consuming xml file from watched folder. Also make one more process variable "inXML" of type xml. Now in SetValue , in location type "/process_data/@inXML" and in expression type "setContentType("/process_data/@inXMLDoc","application/xml")".

So through this you can get your xml file in xml variable named inXML and retrieve content of it using XPath.

Let me know if it resolves ur problem.

Thanks,

Prashast