如何在 Node.js 中膨胀和解码​​ XML?

How can I inflate and decode XML in Node.js?

当我尝试在节点中使用 zlib 进行膨胀和解码​​时,出现错误“错误:不正确的 header 检查

const example = 'pZNBj9owEIX/Sm4+JcYQFrAIUgSqhLRtEWx72MvK6wys1cROPeNu+u/rBGg57O6lp0jj5/nevHGWqJq6lWWgF7uHnwGQkhIRPBln185iaMAfwP8yGr7t7wv2QtSi5BxBBw+ZVh4q12XaNTLPJ9z509PJu9ByMZmMeYidkPcMji3X534sKYm8eQ4EZ4KxpwtiayvoCjZlySY6MVb1Nv5BTRtxlrJGEYYfYpwF5OtY2rjucPjKEV2msO1Yst0U7Kla5CKfwiSdPefjNJ+rebq4Ox7TyUwvcq0Wo3keQVvEELlIylLBxiMxS0fTVIgHcSenuRyJR5Z8j1MMRsbZiCVdU1uU/VAFC95Kp9CgtKoBlKTlofx8L6NQqmuOt1faj++03pHTrmarZa+Wgzu/+p/UGyBVKVJLfttxeV78l+hgu9m52ujfSVnX7nXtQREUjHyIm/rkfAz7fc8iE0PFVOlxkMpgsQVtjgYqxq+Yy9OCanhocesEHSVr18SFGuyThU5puk59q1rXMcc9HFcfRq2l7nWxvIufV+erXUwSdEQ+eBUtOU+XAN5sfj57x+jf09vfZPUH'
const inflated = zlib.inflateSync(Buffer.from(example, 'base64')).toString('ascii')

使用https://www.samltool.com/decode.php我可以成功地对其进行充气和解码,所以这不是输入问题。我是不是用 zlib 做错了什么,或者没有 zlib 有什么办法吗?

您可以使用 inflateRawSync 函数对 Xml 进行膨胀,然后将跳过 header 检查。

const zlib = require("zlib");
const example = 'pZNBj9owEIX/Sm4+JcYQFrAIUgSqhLRtEWx72MvK6wys1cROPeNu+u/rBGg57O6lp0jj5/nevHGWqJq6lWWgF7uHnwGQkhIRPBln185iaMAfwP8yGr7t7wv2QtSi5BxBBw+ZVh4q12XaNTLPJ9z509PJu9ByMZmMeYidkPcMji3X534sKYm8eQ4EZ4KxpwtiayvoCjZlySY6MVb1Nv5BTRtxlrJGEYYfYpwF5OtY2rjucPjKEV2msO1Yst0U7Kla5CKfwiSdPefjNJ+rebq4Ox7TyUwvcq0Wo3keQVvEELlIylLBxiMxS0fTVIgHcSenuRyJR5Z8j1MMRsbZiCVdU1uU/VAFC95Kp9CgtKoBlKTlofx8L6NQqmuOt1faj++03pHTrmarZa+Wgzu/+p/UGyBVKVJLfttxeV78l+hgu9m52ujfSVnX7nXtQREUjHyIm/rkfAz7fc8iE0PFVOlxkMpgsQVtjgYqxq+Yy9OCanhocesEHSVr18SFGuyThU5puk59q1rXMcc9HFcfRq2l7nWxvIufV+erXUwSdEQ+eBUtOU+XAN5sfj57x+jf09vfZPUH'
const inflated = zlib.inflateRawSync(Buffer.from(example, 'base64')).toString('ascii');
console.log("Inflated:", inflated);