javascript - React-Native fetch XML data -
i'm new react-native. trying make simple apps. can't figure out how fetch xml data. json clear , simple.
but how fetch xml? tried convert json via this , other similar scripts, without success. need :/
my code looks simple:
var xml_url = 'http://api.example.com/public/all.xml'; var exampleproject = react.createclass({ getinitialstate: function() { return { data: {results:{}}, }; }, componentdidmount: function() { this.fetchdata(); }, fetchdata: function() { fetch(xml_url) .then((response) => response.json()) .then((responsedata) => { this.setstate({ data: responsedata.data, }); }) .done(); }, render: function() { return ( <view style={styles.wrapper}> <view style={styles.container}> <view style={styles.box}> <text style={styles.heading}>heading</text> <text>some text</text> </view> </view> </view> ); }, });
you can try https://github.com/connected-lab/react-native-xml2js ,
const parsestring = require('react-native-xml2js').parsestring; fetch('link') .then(response => response.text()) .then((response) => { parsestring(response, function (err, result) { console.log(response) }); }).catch((err) => { console.log('fetch', err) })
i use project.
Comments
Post a Comment