在XMLWriter中需先创建文件目录,在此路径基础上创建.xml文件。
private static void builderArrayResources( // E:\Android_learn&practise\Android_International\tobe_resources\MusicPlayer\values // E:\Android_learn&practise\Android_International\tobe_resources\MusicPlayer\values\arrays.xml ArrayList<ArrayEntity> arrayEntities, File file) throws Exception { OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("utf-8"); XMLWriter writer = new XMLWriter(new FileOutputStream(file), format); Document document = DocumentHelper.createDocument(); Element root = document.addElement("resources"); for (ArrayEntity arrayEntity : arrayEntities) { Element arrayElement = root.addElement("string-array"); arrayElement.addAttribute("name", arrayEntity.getName()); List<String> items = arrayEntity.getItems(); for (String item : items) { Element itemElement = arrayElement.addElement("item"); itemElement.setText(item); } } writer.write(document); writer.close(); }
时间: 2024-10-05 18:15:06