-1

I'm looing for a way to extract my data from the below XML file structure:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>**MyClassController**</members>
        <name>ApexClass</name>
    </types>
    <version>51.0</version>
</Package>

The expected result is MyClassController. What is the command I should use and can you please give me a sample?

3
  • I'd use xmlstarlet sel -t -v '//_:members[text()]' input.xml Commented Jul 7, 2021 at 2:19
  • @Shawn, thank you. your suggestion work for me as well. Commented Jul 8, 2021 at 6:04
  • What if you want to do it in a bash file on CI/CD and not able to install startlet or other third party? Commented Aug 28, 2023 at 20:07

1 Answer 1

0

This answer may help How to parse XML using shellscript?

Easier way is, if you know exactly what tag you want you can do

rg -o '<members>(.*)</members>' -r '$1' < your.xml

rg is ripgrep (https://github.com/BurntSushi/ripgrep), a great tool but you need to install

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @Leo Liu , the code works for my case.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.