Solved

Copy XML file and strip off certain elements

Posted on 2016-10-05
4
38 Views
Last Modified: 2016-10-05
I have a XML file that I would like to copy to another location e.g. Folder, Directory.

Then when it's been copied, I need the copied version updated with certain elements removed.

I've attached two files the original that is to be copied and the copied with the elements removed.

Basically, if you look at the original file it has elements that have a BI, RS or IM preceded by an under score.

I need all those elements removed from the file.

So the new file would look like the one I attached to this EE question.

Not sure if this would be easier to do with Windows Batch or VB script.

Thanks
Today.xml
New-copied-Today-file.xml
0
Comment
Question by:rkckjk
  • 3
4 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41829666
Batch:
findstr.exe /v /r "<[A-Z0-9]_BI <[A-Z0-9]_RS <[A-Z0-9]_IM" "C:\Temp\Today.xml" >"C:\Temp\Today_Copied.xml"

Open in new window


Edit: made the RegEx more robust.
0
 
LVL 2

Author Closing Comment

by:rkckjk
ID: 41829672
Thanks a lot
0
 
LVL 83

Expert Comment

by:oBdA
ID: 41829683
Correction for the edited version, sorry:
findstr.exe /v /r "[A-Z0-9]_BI [A-Z0-9]_RS [A-Z0-9]_IM" "C:\Temp\Today.xml" >"C:\Temp\Today_Copied.xml" 

Open in new window

0
 
LVL 83

Expert Comment

by:oBdA
ID: 41829707
And maybe another note: the above only works because the xml source has the nodes you want filtered out on separate, single lines, without inner text or elements.
To treat the file as XML using Powershell:
[xml]$xml = Get-Content -Path "C:\Temp\Today.xml"
$xml.MSR.Info.SelectNodes('*') | % {If ($_.Name -match '\S+_(BI|RS|IM)\Z') {[void]$xml.MSR.Info.RemoveChild($_)}}
$Xml.Save("C:\Temp\Today_Copied.xml")

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now