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