[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 76
  • Last Modified:

Copy XML file and strip off certain elements

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
Richard Kreidl
Asked:
Richard Kreidl
  • 3
1 Solution
 
oBdACommented:
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
 
Richard KreidlSoftware DeveloperAuthor Commented:
Thanks a lot
0
 
oBdACommented:
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
 
oBdACommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now