javascript - XML 到 Javascript/Jquery 可读格式

标签 javascript jquery xml

我有一个大约有 600 行的 XML 文件,我需要将其制作成 JQuery/JavaScript 可读格式,如下例所示:

                    var newSheet = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
                        '<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" mc:Ignorable="x14ac">' +
                        '<cols >' +
                        '<col min="1" max="1" width="24.7" customWidth="1"/>' +
                        '<col min="2" max="2" width="37.7" customWidth="1"/>' +
                        '</cols>' +
                        '<sheetData>' +
                        '<row  r="1">' +
                        '<c t="inlineStr" r="A1" s="7">' +
                        '<is>' +
                        '<t>Information sheet</t>' +
                        '</is>' +
                        '</c>' +
                        '</row>' +
                        '<row  r="2">' +
                        '<c t="inlineStr" r="A2" s="2">' +
                        '<is>' +
                        '<t>Created by</t>' +
                        '</is>' +
                        '</c>' +
                        '<c t="inlineStr" r="B2" s="3">' +
                        '<is>' +
                        '<t>F12Magic</t>' +
                        '</is>' +
                        '</c>' +
                        '</row>' +
                        '<row  r="3">' +
                        '<c t="inlineStr" r="A3" s="2">' +
                        '<is>' +
                        '<t>Date</t>' +
                        '</is>' +
                        '</c>' +
                        '<c t="inlineStr" r="B3" s="3">' +
                        '<is>' +
                        '<t>' + '</t>' +
                        '</is>' +
                        '</c>' +
                        '</row>' +
                        '</sheetData>' +
                        '<mergeCells count="1">' +
                        '<mergeCell  ref="A1:B1"/>' +
                        '</mergeCells>' +
                        '</worksheet>';

如您所见,引号和“+”号都是为了让 JQuery/JavaScript 可读。有没有办法将 XML 文件转换为上述格式以便它可以读取?

如您所想:我不会用引号和“+”号将 600 行括起来。

最佳答案

您可以将反引号用作 this为了便于阅读,帖子建议在新行开始之前在每行之后加一个反斜杠。

var foo = `Bob
is
cool`;

关于javascript - XML 到 Javascript/Jquery 可读格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56579828/

相关文章:

javascript - 根据选中的复选框组合重定向到不同的页面

javascript - ES6 : share data between modules

jquery - 使用 jQuery 根据 div 中的时间和当前时间向 div 添加不同的类?

java - 如何使用j2se从xml文件中获取数据

php - 使用php将xml转换为mysql?

java - 通过 jdom 访问具有给定名称的子项

javascript - 分享此 API Facebook 分享图片未显示

javascript - 使用 Ajax 获取数据未定义

javascript - Ajax Post 上的 Json 基元无效

javascript - 手动编辑日期或清除日期时, Bootstrap 日期选择器更改日期事件不会触发