I was using a node module xmldom. However, it always prints out a huge chunk of warnings and errors like the following:
@#[line:484,col:1]
[xmldom warning] attribute "hidden" missed quot(")!!
@#[line:517,col:1]
[xmldom warning] unclosed xml attribute
@#[line:517,col:1]
[xmldom warning] unclosed xml attribute
@#[line:518,col:1]
[xmldom warning] attribute "center" missed quot(")!!
@#[line:522,col:1]
[xmldom warning] attribute "6" missed quot(")!!
I was wondering how to explicitly silent all those warnings and errors without touching node or package.json themselves?
I luckily found the answer with a reference to this question. The workaround for me is to replace the original dom
instantiation:
var doc = new dom().parseFromString(body);
with the following options
:
var doc = new dom({
locator: {},
errorHandler: { warning: function (w) { },
error: function (e) { },
fatalError: function (e) { console.error(e) } }
}).parseFromString(body);
We must understand that hiding the warnings and errors could not solve the problem. Therefore, I suggest using this techniques only when the correctness of the input have no impact on the later logics, or the warning messages are overwhelming the other console messages.
Hope it helps the communities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With