Skip to main content
added 229 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Assuming the following (modified) XML:

<?xml version="1.0"?>
<root>
  <ContactPerson>
    <GivenName>John</GivenName>
    <FamilyName>Wayne</FamilyName>
    <PhoneFixList>
      <PhoneFix>78787878</PhoneFix>
    </PhoneFixList>
    <EmailList>
      <Email>[email protected]</Email>
    </EmailList>
  </ContactPerson>
  <ContactPerson>
    <GivenName>James</GivenName>
    <FamilyName>Stewart</FamilyName>
    <PhoneFixList>
      <PhoneFix>90909090</PhoneFix>
    </PhoneFixList>
    <EmailList>
      <Email>[email protected]</Email>
    </EmailList>
  </ContactPerson>
</root>

The XMLStarlet invocation

xml sel -t -m '//ContactPerson' -v 'concat(GivenName, " ", FamilyName, " ", PhoneFixList/PhoneFix, " ", EmailList/Email)' -nl file.xml

produces

John Wayne 78787878 [email protected]
James Stewart 90909090 [email protected]

The invocation of XMLStarlet contains an implicit loop over all ContactPerson nodes, and for each of these, the specific fields are concatenated to produce the correct output. The -nl at the end causes a newline to be printed.

Assuming the following (modified) XML:

<?xml version="1.0"?>
<root>
  <ContactPerson>
    <GivenName>John</GivenName>
    <FamilyName>Wayne</FamilyName>
    <PhoneFixList>
      <PhoneFix>78787878</PhoneFix>
    </PhoneFixList>
    <EmailList>
      <Email>[email protected]</Email>
    </EmailList>
  </ContactPerson>
  <ContactPerson>
    <GivenName>James</GivenName>
    <FamilyName>Stewart</FamilyName>
    <PhoneFixList>
      <PhoneFix>90909090</PhoneFix>
    </PhoneFixList>
    <EmailList>
      <Email>[email protected]</Email>
    </EmailList>
  </ContactPerson>
</root>

The XMLStarlet invocation

xml sel -t -m '//ContactPerson' -v 'concat(GivenName, " ", FamilyName, " ", PhoneFixList/PhoneFix, " ", EmailList/Email)' -nl file.xml

produces

John Wayne 78787878 [email protected]
James Stewart 90909090 [email protected]

Assuming the following (modified) XML:

<?xml version="1.0"?>
<root>
  <ContactPerson>
    <GivenName>John</GivenName>
    <FamilyName>Wayne</FamilyName>
    <PhoneFixList>
      <PhoneFix>78787878</PhoneFix>
    </PhoneFixList>
    <EmailList>
      <Email>[email protected]</Email>
    </EmailList>
  </ContactPerson>
  <ContactPerson>
    <GivenName>James</GivenName>
    <FamilyName>Stewart</FamilyName>
    <PhoneFixList>
      <PhoneFix>90909090</PhoneFix>
    </PhoneFixList>
    <EmailList>
      <Email>[email protected]</Email>
    </EmailList>
  </ContactPerson>
</root>

The XMLStarlet invocation

xml sel -t -m '//ContactPerson' -v 'concat(GivenName, " ", FamilyName, " ", PhoneFixList/PhoneFix, " ", EmailList/Email)' -nl file.xml

produces

John Wayne 78787878 [email protected]
James Stewart 90909090 [email protected]

The invocation of XMLStarlet contains an implicit loop over all ContactPerson nodes, and for each of these, the specific fields are concatenated to produce the correct output. The -nl at the end causes a newline to be printed.

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Assuming the following (modified) XML:

<?xml version="1.0"?>
<root>
  <ContactPerson>
    <GivenName>John</GivenName>
    <FamilyName>Wayne</FamilyName>
    <PhoneFixList>
      <PhoneFix>78787878</PhoneFix>
    </PhoneFixList>
    <EmailList>
      <Email>[email protected]</Email>
    </EmailList>
  </ContactPerson>
  <ContactPerson>
    <GivenName>James</GivenName>
    <FamilyName>Stewart</FamilyName>
    <PhoneFixList>
      <PhoneFix>90909090</PhoneFix>
    </PhoneFixList>
    <EmailList>
      <Email>[email protected]</Email>
    </EmailList>
  </ContactPerson>
</root>

The XMLStarlet invocation

xml sel -t -m '//ContactPerson' -v 'concat(GivenName, " ", FamilyName, " ", PhoneFixList/PhoneFix, " ", EmailList/Email)' -nl file.xml

produces

John Wayne 78787878 [email protected]
James Stewart 90909090 [email protected]