/    Sign up×
Community /Pin to ProfileBookmark

How to delete the content values of all elements?

How can I most easily delete all values of all <name>…..</name> elements of a certain *.xml file?

the <name> element tags should be kept.

A command line tool and command would be preferred rather than a GUI based tool.

The <name> elements contain only value and no further nested elements.

to post a comment

6 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumSep 21.2020 — Would a powershell script be OK for your?
Copy linkTweet thisAlerts:
@psteinauthorSep 25.2020 — Yes, that would be fine.

Do you have one?
Copy linkTweet thisAlerts:
@SempervivumSep 25.2020 — Not yet. Some time ago I had a similar task. I'm going to dig out that script and modify it according to your requirement ...
Copy linkTweet thisAlerts:
@SempervivumSep 25.2020 — Done. This script processes all xml file recursively. If this is not requested we have to adjust it a bit.
# Get all xml files
$files = Get-ChildItem -Filter *.xml -File -Recurse
ForEach ($file in $files) {
# Read xml from file
$xml = Get-Content -Path $file.FullName
# empty name tags
$xml = $xml -Replace "&lt;name&gt;.*?&lt;/name&gt;", "&lt;name&gt;&lt;/name&gt;"
# Write-Host $xml
# Write xml back to file
Set-Content -Path $file.FullName -Value $xml
}
Read-Host -Prompt "Press Enter to exit"
You know how to run the powershell script?

Don't forget to backup your original xml files in case the script doesn't work as expected.
Copy linkTweet thisAlerts:
@psteinauthorSep 27.2020 — Ok, thank you.

I will check it.

My initial question was only simplified
Copy linkTweet thisAlerts:
@VITSUSASep 28.2020 — @pstein#1623689 Have you got the solution?
×

Success!

Help @pstein spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 3.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...