2

Input XML looks like several blocks of:

<Parties>
  <Party compid="CUST1" side="1">
                <Connections>
                    <SocketConnection listenport="9029" />
                </Connections>
   </Party>
</Parties>

My goal is to extract to each customer his specific params like: compid;listenport

By now I can get all customers using

xmlstarlet fo -D config.xml | xmlstarlet select -T -t -m '//Parties/Party' -v '@compid' -nl

Next step would be a loop for each customer to get his listenport, but

xmlstarlet fo -D config.xml | xmlstarlet select -T -t -m '//Parties/Party[@compid="CUST1"]' -v 'Connections/SocketConnection/@listenport'

or any other try returns nothing. Am I missing something at filtering using [@value=string]?

Thanks in advance!

0

1 Answer 1

1

With your example and xmlstarlet:

xmlstarlet select --text --template --match '//Parties/Party' --value-of \
  'concat(@compid,";",Connections/SocketConnection/@listenport)' -n config.xml

Output:

CUST1;9029

See: xmlstarlet select --help

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.