1

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>';

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?

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

Aids Jung
  • 63
  • 1
  • 7
  • What do you mean by read it? Do want to parse it on javascript to do further operations? You could go through [this](https://stackoverflow.com/questions/7949752/cross-browser-javascript-xml-parsing) answer for parsing it as xml. – shrys Jun 13 '19 at 11:59
  • It needs to be in a readable format for Javascript with the quotation marks/and + signs. I can't be the only one looking for a easier way to do that. @shrys – Aids Jung Jun 13 '19 at 12:05
  • 1
    You can use back ticks as [this](https://stackoverflow.com/a/40334713/4051471) post suggests or put a back slash after each line before new line starts, for readability – shrys Jun 13 '19 at 12:29
  • Exactly what I needed, thanks @shrys – Aids Jung Jun 13 '19 at 12:41

1 Answers1

2

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`;
shrys
  • 5,860
  • 2
  • 21
  • 36