XML到Javascript/Jquery可读格式 [英] XML to Javascript/Jquery readable format

查看:70
本文介绍了XML到Javascript/Jquery可读格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a XML file with approximately 600 lines, I need to make it in a JQuery/JavaScript readable format like the example below:

                    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文件转换为上述格式,以便它可以读取它?

As you can see, the quotation marks and the '+' sign are all there to make it readable for JQuery/JavaScript. Is there a way to convert the XML file to above format so that it can read it?

您可以想象:我不会用引号和'+'包围600行.

As you can imagine: I am not going to surround 600 lines with the quotation marks and the '+' sign.

推荐答案

您可以使用反引号作为帖子建议或为了便于阅读,在新行开始之前在每行之后添加反斜杠.

You can use back ticks as this post suggests or put a back slash after each line before new line starts, for readability.

var foo = `Bob
is
cool`;

这篇关于XML到Javascript/Jquery可读格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆