?
Solved

Copy XML file and strip off certain elements

Posted on 2016-10-05
4
Medium Priority
?
72 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:Richard Kreidl
[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 85

Accepted Solution

by:
oBdA earned 2000 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:Richard Kreidl
ID: 41829672
Thanks a lot
0
 
LVL 85

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 85

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 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