Jump to content
Macro Express Forums

Recommended Posts

I am trying to edit an XML file by deleting all text between certain tags, including the tags themselves. For instance:




could be part of the XML file. I would want to delete all text between the tags "<system-layout>" and "</system-layout>", including the tags themselves. The tags could occur multiple times in any given XML file. I wish there were an option in ME to "delete substring" within the text variable I assign the XML content to, where the content between the tags could be represented by wildcard characters, such as "delete "<system-layout>*</system-layout>" (you get the drift).


I'm sure there I could come up with something by splitting the text string multiple times (yada yada), but that seems like a pain.


Anybody have a "simple" solution to this problem?









Link to comment
Share on other sites

  • 4 weeks later...

I can't think of a simple way.


In cases like these in past using just MEP I simply pull the file contents into a variable, find the position of the tags, do some simple math, and delete sub-string based on position. But if you do it multiple times it becomes a little more challenging because the 'find' will find the first occurrence again. One of many ways to handle this is to chunk the file contents from one variable to another. IE find the first tag, add the tag length, copy that chunk to a temp var, append the temp to the results var, delete that chunk from the original var. Find the closing tag, do some math, delete that chunk without copy, add just the ending tag to the results var. Now put that in a loop and when the 'find position' returns zero append the remainder of the var to the results var.


Definitely not simple or elegant but it's simple to understand and easy enough to hack out. And I'd create a macro just for this to use as a subroutine to keep my code clean. If you're interested I could write it for you for your quickly for a minimal fee.

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.

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.

  • Create New...