MakaPakaTobyHannah Posted July 2, 2013 Report Share Posted July 2, 2013 I am trying to edit an XML file by deleting all text between certain tags, including the tags themselves. For instance: <system-layout> <system-margins> <left-margin>22</left-margin> <right-margin>0</right-margin> </system-margins> <top-system-distance>218</top-system-distance> </system-layout> 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? Cheers, MakaPaka Quote Link to comment Share on other sites More sharing options...
Cory Posted July 25, 2013 Report Share Posted July 25, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.