Jump to content

Structure text conversion to XML


Recommended Posts

I have a txt file that was exported from a system, this file is following a structure form. I would like to convert this file into xml format in order to do a report. An example of the file is described below. STEP NAME="LAST_STEP" { RECTANGLE= { X=945 Y=372 H=40 W=100 } ACTION NAME="A1" { DESCRIPTION="Step msg" ACTION_TYPE=ASSIGN QUALIFIER=P EXPRESSION="'^/MSG.CV' := ""Calc Complete. Press Start to Transfer.""" DELAY_TIME=0 } ACTION NAME="A3" { DESCRIPTION="Enable Subordinate Failures" ACTION_TYPE=ASSIGN QUALIFIER=P EXPRESSION="'^/MONITOR/SUB1_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB2_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB3_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB4_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB5_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB6_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB7_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB8_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB9_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB10_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB11_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB12_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB13_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB14_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB15_FAIL/DISABLE.CV' := 0;'^/MONITOR/SUB16_FAIL/DISABLE.CV' := 0;" DELAY_TIME=0 }

Link to post
Share on other sites

The process should be performed automatically, since I'm only showing part of the txt file ( the complete file has a lot of code similar to what I present.I don't know what is used to convert the file to the format that I present due that this is a proprietary software. In terms of the software available that I could use, I'm open to suggestion. I have experienced with C++ and visual basic, but if there is a more easy way I will use it

Link to post
Share on other sites

This might not be absolutely necessary for you at the moment, as it's an entire field of study in computer science, but knowing grammar (computer science term) would give you a good idea how to make the program: http://en.wikipedia.org/wiki/Formal_grammarBut to break this down to a simple algorithm you could build, you must define a set of rules for the source and target languages, and then read and write following those rules.Your language seems a bit complicated, because you have two cases where different syntaxes are used for the same purpose:

STEP NAME="LAST_STEP"{

and

RECTANGLE={

You must define a list of all the rules that your syntax follows. Here's a couple of them:

  1. The first few characters from A-Z (and maybe 0-9?) define the type of object.
  2. After a type identifier can go three things:* An opening curly bracket indicating a set of objects that are children to this one.* An equals sign, indicating that this object has one value. The value of this object follows the equals sign and has its own set of rules which need to be defined.* A syntax with its own set of rules (A-Z0-9 followed by an = and then a values which may be quoted) indicating a property of the object. Following this syntax must go the curly brace mentioned before.

And so on, I could keep defining all the rules your document follows, but only you know for certain what characters are and aren't allowed in each part.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...