1

I'm getting my feet wet with xidel and want to use it together with namesilo.com API for updating DNS records. I'm having trouble constructing the right selector. Let's say, I had the following xml response, how would I go about selecting the record_id for host www.mydomain.org?

<?xml version="1.0"?>
<namesilo>
  <request>
    <operation>dnsListRecords</operation>
    <ip>62.157.5.106</ip>
  </request>
  <reply>
    <code>300</code>
    <detail>success</detail>
    <resource_record>
      <record_id>7e1abd117be5506febe327ab906f67c7</record_id>
      <type>A</type>
      <host>www.mydomain.org</host>
      <value>182.245.2.23</value>
      <ttl>172817</ttl>
      <distance>0</distance>
    </resource_record>
    <resource_record>
      <record_id>7e75694e3da869315b92d386dcbed45b</record_id>
      <type>A</type>
      <host>m.mydomain.org</host>
      <value>21.148.13.45</value>
      <ttl>172817</ttl>
      <distance>0</distance>
    </resource_record>
  </reply>
</namesilo>

I haven't gotten past xidel --extract //resource_record, really. All attempts at //resource_record[host="www.mydomain.org"]/record_id and similar have failed so far. Piping through grep and sed would work via xidel --extract //resource_record | grep www.mydomain.org | sed s/www.mydomain.org.*// on the raw, unprettified XML-response from namesilo.com, I guess, but I'm sure there is a better way.

leggewie
  • 242
  • 2
  • 9
  • 1
    Couldn't replicate your problem on your sample xml; my output was `7e1abd117be5506febe327ab906f67c7`. – Jack Fleeting Jun 30 '20 at 21:01
  • 1
    You didn't mention the OS you're using. `-e '//resource_record[host="www.mydomain.org"]/record_id'` for Unix. `-e "//resource_record[host='www.mydomain.org']/record_id"` for Windows. – Reino Jun 30 '20 at 22:24
  • Thanks, @Reino. The problem was the missing ' apostrophe. I am on Unix. – leggewie Jul 02 '20 at 09:35

2 Answers2

1

Does not work: xidel -e //resource_record[host="www.mydomain.org"]/record_id

Generally speaking it's recommended to quote a (extraction) query. That doesn't mean it won't work without quotes:

xidel -s <input> -e //resource_record\[host=\"www.mydomain.org\"\]/record_id
7e1abd117be5506febe327ab906f67c7

It's just that you have to prevent certain characters from being interpreted by Bash's shell by escaping them.

Reino
  • 3,203
  • 1
  • 13
  • 21
0

Does not work: xidel -e //resource_record[host="www.mydomain.org"]/record_id

Works: xidel -e '//resource_record[host="www.mydomain.org"]/record_id'

leggewie
  • 242
  • 2
  • 9