0

I have an HTTP response that is formed like this:

<records>
<record>
<f id="60">
ANT708-1-BA-M110-001-IFC.PDF
<url>
https://hardermech.quickbase.com/up/bi8vxepu8/g/r9p6/eb6/va/ANT708-1-BA-M110-001-IFC.PDF
</url>
</f>
<f id="276">1</f>
<update_id>1496326605486</update_id>
</record>
</records>

How can I access the data value "1" for "f id 276" with Google Script?

1 Answer 1

1

How about following sample script?

XmlService is used for this script. The detail information is https://developers.google.com/apps-script/reference/xml-service/xml-service.

Sample Script :

function sample() {
  var data = '\
    <records> \
      <record> \
        <f id="60"> \
        ANT708-1-BA-M110-001-IFC.PDF \
        <url> \
        https://hardermech.quickbase.com/up/bi8vxepu8/g/r9p6/eb6/va/ANT708-1-BA-M110-001-IFC.PDF \
        </url> \
        </f> \
        <f id="276">1</f> \
        <update_id>1496326605486</update_id> \
      </record> \
    </records>'

  var xml = XmlService.parse(data);
  var items = xml.getRootElement().getChild('record').getChildren('f');
  var res
  for (var i in items) {
    if (items[i].getAttribute('id').getValue() == 276) {
      res = items[i].getValue();
    }
  }
  Logger.log(res) // 1 is retrieved.
}

The value is in f of record. Since there are several f, it searches the attribute id as an array. And the result 1 is retrieved.

If I misunderstand your question, I'm sorry.

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.