在HarmonyOS NEXT开发中ohos.xml写好xml后怎么以文件形式存起来?问题描述
// 1.基于Arraybuffer构造XmlSerializer对象
let arrayBuffer: ArrayBuffer = new ArrayBuffer(2048); // 创建一个2048字节的缓冲区
let thatSer: xml.XmlSerializer = new xml.XmlSerializer(arrayBuffer); // 基于Arraybuffer构造XmlSerializer对象
thatSer.setDeclaration(); // 写入xml的声明
thatSer.startElement(‘bookstore’); // 写入元素开始标记
thatSer.startElement(‘book’); // 嵌套元素开始标记
thatSer.setAttributes(‘category’, ‘COOKING’); // 写入属性及属性值
thatSer.startElement(‘title’);
thatSer.setAttributes(‘lang’, ‘en’);
thatSer.setText(‘Everyday’); // 写入标签值
thatSer.endElement(); // 写入结束标记
thatSer.startElement(‘author’);
thatSer.setText(‘Giada’);
thatSer.endElement();
thatSer.startElement(‘year’);
thatSer.setText(‘2005’);
thatSer.endElement();
thatSer.endElement();
thatSer.endElement();
怎么以文件的形式存起来?比如filename.xml
解决方案
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides...