Jump to content
Macro Express Forums
Sign in to follow this  
MakaPakaTobyHannah

Editing an XML file

Recommended Posts

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

 

 

 

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×