react-native - React Native:如何读取和显示 xml 文件
问题描述
如何将 .xml 文件显示到屏幕上。我可以使用显示 pdf 文件,react-native-pdf
但如何在 .XML 文件中显示文本或阅读它。
解决方案
解决方案在 .XML 文件中显示文本或阅读
我正在向您展示如何读取任何文件。如果您可以读取任何文件,并将其存储到某种状态,那么渲染就不是问题,我希望如此。
以下是如何在 react-native 中读取本地文件:
var RNFS = require('react-native-fs');
import DocumentPicker from 'react-native-document-picker';
selectFiles = () => {
let that = this;
try {
DocumentPicker.pickMultiple({
type: [DocumentPicker.types.allFiles],
}).then((results) => {
console.log(results[0]);
//that.setState({language: results[0].type});
RNFS.readFile(results[0].uri)
.then((file) => {
that.setState({
code: file
});
})
.catch((error) => console.log('err: ' + error));
//the `code` state holds your xml file, just display it however you want... use 3rd party library for syntax highlight or whatever you want
});
} catch (err) {
if (DocumentPicker.isCancel(err)) {
// User cancelled the picker, exit any dialogs or menus and move on
} else {
throw err;
}
}
};
推荐阅读
- javascript - 如何在 Vuejs 中获取路径的当前名称(例如“this”值)?
- apache-spark - 使用 DBR 7.3.x+ 将 XML 文件加载到 PySpark 中的数据框
- excel - 没有 VBA 的 Excel:如何从列中创建序列号跟随模式
- floating-point - GAS 汇编器打印浮点数
- redis - 使用 Digital Ocean 托管实例的 Redis 性能
- java - 如何在单击按钮时将自定义布局添加到线性布局
- azure - SonarQube Azure AD 集成
- batch-file - 使用 bat 文件设置系统变量
- go - go-gin中如何调用接口函数?
- flutter - 如何在 Flutter 的时间序列图中添加多条线