I'm making and ajax request to an API that sends back XML format. With the following code the responseXml data gets printed out, but I don't know how I can parse it and access the data (like item.line or item.origTime).
Should I use JSON parser somehow or something else?
class App extends Component {
constructor(props) {
super(props);
this.state = { schedules: [] };
fetch('http://api.bart.gov/api/sched.aspx?cmd=stnsched&key=' + API_KEY + '&orig=12th&date=today')
.then((response) => response.text())
.then((responseXML) => {
this.setState({schedules: responseXML});
console.log(responseXML);
})
.catch((error) => {
console.log(error);
});
}
render () {
return (
<div>
<SelectList />
<TimeTable schedules={this.state.schedules} />
</div>
)
}
}
xml response
<root>
<uri>...</uri>
<date>7/22/2016</date>
<sched_num>39</sched_num>
<station>
<name>12th St. Oakland City Center</name>
<abbr>12TH</abbr>
<item line="ROUTE 7" trainHeadStation="MLBR" origTime="4:36 AM" destTime="5:21 AM" trainIdx="1" bikeflag="1"/>
<item line="ROUTE 2" trainHeadStation="PITT" origTime="4:37 AM" destTime="5:17 AM" trainIdx="1" bikeflag="1"/>
<item line="ROUTE 3" trainHeadStation="RICH" origTime="4:37 AM" destTime="5:00 AM" trainIdx="1" bikeflag="1"/>
<item line="ROUTE 1" trainHeadStation="SFIA" origTime="4:43 AM" destTime="5:28 AM" trainIdx="1" bikeflag="1"/>
......