Jump to content
Macro Express Forums

Copy part of a text file by lines rather than amount of characters?


Dean
 Share

Recommended Posts

Hello, stupid question.

 

Have a large text file that is an XML styled file with repeating nested tag style.

I would like save portions of the text file out to seperate text files.

 

The sections I want to save begin and end with a tag.

eg.

<dataset

fielda="xxxxxxxxxxxx"

fieldb="xxxxxx"

fieldc="xxxxxx"

<value>example1</value>

</dataset>

 

I am attempting to use the Text file process feature of Macro Express.

Silly question: How do I copy what is between the <dataset and </dataset> tags?, and save out as a textfile

example1.txt

 

I thought I could use the copy part of text file feature, and target the <dataset tag, and then specify the amount of lines, but thats when I got stuck, as it only has option to specify a fixed number of characters,

which differ radically between each dataset.

 

Please excuse my ignorance people, but is the above possible with Macro Express?.

 

Thankyou kindly for your time.

 

..Dean..

Link to comment
Share on other sites

<dataset
   fielda="xxxxxxxxxxxx"
   fieldb="xxxxxx"
   fieldc="xxxxxx"
   <value>example1</value>
 </dataset>

Read the content of the file into a variable. Set one integer variable to the location of '<dataset'. Set another integer variable to the location of '</dataset>'. Then copy the data between. This untested sample should get you started:

 

// Read content of file into a variable
Variable Set String set %Content% to the contents of c:\TheFile.xml
Variable Set Integer %Start% to the position of "<dataset" in %Content% // Find position of <dataset
Variable Modify Integer: %Start% = %Start% + 8 // Adjust to skip over <dataset
Variable Set Integer %End% to the position of "</dataset>" in %Content% // find position of </dataset>

// Copy the data between the tags
Variable Modify String: Copy a substring in %Content%, starting at %Start% and %End% characters long to %OneTag%

After processing one tag you could delete it from the %Content% variable to get ready to process the next variable.

Link to comment
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...
 Share

×
×
  • Create New...