在HarmonyOS NEXT开发中ohos.xml写好xml后怎么以文件形式存起来?

在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

阅读 956
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
logo
HarmonyOS
子站问答
访问
宣传栏