Solved

Copy XML file and strip off certain elements

Posted on 2016-10-05
4
27 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

21 Experts available now in Live!

Get 1:1 Help Now