Solved

Copy XML file and strip off certain elements

Posted on 2016-10-05
4
64 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 84

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 84

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 84

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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