【问题标题】:XML to Javascript/Jquery readable formatXML 到 Javascript/Jquery 可读格式
【发布时间】:2019-10-28 00:12:11
【问题描述】:

我有一个大约 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 行括起来。

【问题讨论】:

  • 阅读是什么意思?是否想在 javascript 上对其进行解析以进行进一步操作?您可以通过 this 答案将其解析为 xml。
  • 它必须是带有引号/和 + 符号的 Javascript 可读格式。我不能成为唯一一个寻找更简单方法的人。 @shrys
  • 您可以按照this 帖子的建议使用反引号,或者在新行开始之前在每行之后放置一个反斜杠,以提高可读性
  • 正是我需要的,谢谢@shrys

标签: javascript jquery xml


【解决方案1】:

您可以按照this 帖子的建议使用反引号,或者在新行开始之前在每行之后放置一个反斜杠,以提高可读性。

var foo = `Bob
is
cool`;

【讨论】:

  • 即使尝试但输出相同
猜你喜欢
  • 1970-01-01
  • 2017-03-12
  • 2014-08-11
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
  • 2016-08-06
相关资源
最近更新 更多