95 lines
2.2 KiB
JavaScript
95 lines
2.2 KiB
JavaScript
const fs = require('fs');
|
|
const cheerio = require('cheerio');
|
|
const Swal = require('sweetalert2')
|
|
|
|
function saveXmlToFile(xmlData, filePath) {
|
|
// Check if the file path is provided
|
|
if (!filePath) {
|
|
console.error('File path is required.');
|
|
return;
|
|
}
|
|
|
|
// Write the XML data to the specified file path
|
|
fs.writeFile(filePath, xmlData, 'utf8', (err) => {
|
|
if (err) {
|
|
console.error('Error writing XML file:', err);
|
|
} else {
|
|
console.log('XML file saved successfully.');
|
|
|
|
// Clear all data in local storage
|
|
localStorage.clear();
|
|
|
|
}
|
|
});
|
|
localStorage.clear();
|
|
|
|
window.location.href = 'dashboard.html';
|
|
|
|
}
|
|
|
|
|
|
function savexml(UserFilename) {
|
|
|
|
// Get the XML string from localStorage
|
|
var xmlString = localStorage.getItem("xml");
|
|
|
|
// Get the json string from localStorage for set fileName
|
|
var jsonData = localStorage.getItem("json");
|
|
|
|
// Create a filename using on the subtitle
|
|
var xmlfilename = `${UserFilename}.xml`;
|
|
// var jsonfilename = `${UserFilename}.json`;
|
|
|
|
// file path where you want to save the XML file
|
|
const xmlfilePath = process.cwd() + '/xml/' + xmlfilename;
|
|
// const jsonfilePath = process.cwd() + '/xml/' + jsonfilename;
|
|
|
|
// Call the function to save the XML file
|
|
saveXmlToFile(xmlString, xmlfilePath);
|
|
|
|
}
|
|
|
|
function promptBox(){
|
|
|
|
|
|
var jsonData = localStorage.getItem("json");
|
|
var jsonString = JSON.parse(jsonData);
|
|
var getTitle = jsonString.question_paper_title;
|
|
var RawFileName = removeHtmlTags(getTitle);
|
|
console.log(RawFileName)
|
|
|
|
Swal.fire({
|
|
title: 'Enter Filename',
|
|
input: 'text',
|
|
inputValue: RawFileName,
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Submit',
|
|
cancelButtonText: 'Cancel',
|
|
inputValidator: (value) => {
|
|
if (!value) {
|
|
return 'You need to enter Filename!'
|
|
}
|
|
}
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
|
|
const inputValue = result.value
|
|
savexml(inputValue)
|
|
|
|
}
|
|
})
|
|
|
|
|
|
}
|
|
|
|
// function using for REMOVE HTML ELEMENT in the String
|
|
function removeHtmlTags(inputString) {
|
|
|
|
const $ = cheerio.load(inputString);
|
|
const text = $.text();
|
|
|
|
return text;
|
|
}
|
|
|
|
|
|
|