3

I've been trying to get through this with different options and couldn't find the correct way of doing it. Here is the xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
  <types>
        <members>PriceRule__c.All</members>
        <members>PriceRule__c.None</members>
        <members>ProductRule__c.All</members>
        <members>Quote__c.All_Quotes</members>
        <members>SummaryVariable__c.All</members>
        <name>ListView</name>
  </types>
  <types>
        <members>*</members>
        <name>AnalyticSnapshot</name>
  </types>
</Package>

I want to be able to get the text of the "name" node that is in the same "types" node for any "members" node that starts with PriceRule__c. Here is the furthest I could get which was to actually find the values of those nodes:

echo $(xmlstarlet sel -N x="http://soap.sforce.com/2006/04/metadata" -t -v "//x:types/*[starts-with(text(),'PriceRule__c')]" test.xml)

This prints out:

PriceRule__c.All PriceRule__c.None

But what I need is a way to get the value ListView Any idea how the XPath should be to get that? Thank you in advance!

1 Answers1

3

Change your XPath to

//x:types[starts-with(x:members,'PriceRule__c')]/x:name

and you will select the x:name with value, ListView, as requested.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • I'm not clear on what the "x:" is for/represents in the example. – Bill Hileman May 25 '17 at 20:23
  • 2
    @BillHileman: It is a namespace prefix, defined by OP via `-N` in xmlstarlet to cover the default namespace in the XML document. See [***How does XPath deal with XML namespaces?***](https://stackoverflow.com/questions/40796231/how-does-xpath-deal-with-xml-namespaces) – kjhughes May 25 '17 at 20:41