Cleand up XML code

This commit is contained in:
2023-05-18 15:29:39 +02:00
parent 92df5abf9c
commit 081ce03d38

View File

@@ -77,7 +77,7 @@ function showHeadersHistory(element){
showPopup(); showPopup();
} }
function formatXML(xml) { async function formatXML(xml) {
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8082 + "/prettify"; const address = window.location.protocol + "//" + window.location.hostname + ":" + 8082 + "/prettify";
var data = { var data = {
data: xml, data: xml,
@@ -86,27 +86,19 @@ function formatXML(xml) {
version: "1.0" version: "1.0"
} }
console.log("formattedXML"); var init = {
fetch(address, { body: JSON.stringify(data),
method: 'POST', method: "POST"
body: JSON.stringify(data) };
}) var request = new Request(address, init);
.then(async (response) => {
const promise = response.json(); var result = await fetch(request).then(response => {
if (!response.ok) { return response.text().then(function (text) {
throw Error(await promise); return JSON.parse(text);
}
return promise;
})
.then((data) => {
document.getElementById('code-highlight-content').innerText = data.result;
highlightSyntax('code-highlight-content');
//console.log(data.result);
})
.catch((error) => {
console.error('Error:', error);
}); });
});
return result;
} }
function showRequestBody(element){ function showRequestBody(element){
@@ -138,15 +130,22 @@ function showRequestBody(element){
break; break;
} }
case "application/xml":{ case "application/xml":{
//document.getElementById('code-highlight-content').innerText = historyRequestBody; document.getElementById('code-highlight-content').innerText = "";
formatXML(historyRequestBody); formatXML(historyRequestBody).then(function(result) {
if (result.status == "OK") {
document.getElementById('code-highlight-content').innerText = result.result;
highlightSyntax('code-highlight-content');
}
else {
document.getElementById('code-highlight-content').innerText = historyRequestBody;
}
});
break; break;
} }
default:{ default:{
requestBody = '<code>'+historyRequestBody+'</code>'; document.getElementById('code-highlight-content').innerText = historyRequestBody;
document.getElementById('history-request-body-content').innerText = requestBody;
hljs.highlightElement(document.getElementById('history-request-body-content')); hljs.highlightElement(document.getElementById('history-request-body-content'));
} }
} }