This is the data stream, (Hope I’m displaying this correctly, it took me forever to figure it out). I was just trying to extract the title just to see if I could get it to work. I obviously am lost and don’t understand why I keep getting errors.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<items total="475974">
<link href="https://www.sciencebase.gov/catalog/items?
max=1&s=Search&q=water&format=xml"
rel="self" />
<link href="https://www.sciencebase.gov/catalog/items?
max=1&s=Search&q=water&format=xml&offset=1"
rel="next" />
<item id="4f4e4a62e4b07f02db6369dc">
<link href="https://www.sciencebase.gov/catalog/
item/4f4e4a62e4b07f02db6369dc" rel="self" />
<oldId>1800335</oldId>
<title>Reconnaissance of the water resources of Beaver County,
Oklahoma</title>
<summary>Ground water is the major source of water supply in Beaver
County. Because of the rapidly increasing demand for the limited
supply of water for irrigation, additional geologic and hydrologic
data are needed for management of ground-water resources...</summary>
</item>
</items>
And this is my code:
function myFunction() {
var response = UrlFetchApp.fetch("http://www.sciencebase.gov/catalog
/items?s=Search&q=water&format=xml&max=1").getContentText();
var parsedResponse = Xml.parse(response, true);
//I tried this but it didn't work
var title = parsedResponse.html.head.getElements("title");
Browser.msgBox(title);
}
I always use a tool to look at XML. If you need one, in Chrome, I use the XML Tree extension. Install it, visit your test URL and you’ll see formatted XML that’s expandable and collapsable (just like IE 🙂 and makes it easy to see the structure.
Here’s your code with some mods and light narration:
Logs the following 10 titles:
Hope this helps, let me know if you need anything further clarified.