You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that cheerio cannot see the root element I've supplied and isn't wrapping the new element into the root as a result of that
constcheerio=require('cheerio');consterrorDoc=cheerio.load(`<error></error>`,{xml: true})console.log(errorDoc.root().prop('outerHTML'));// ^^^ First red flag as I'd expect it to return the <error /> elementerrorDoc.root().prepend(`<message>yooo</message>`);console.log(errorDoc.xml());// '<message>yoo</message><error/>'// ^^^ The real issue here
And with .append()
constcheerio=require('cheerio');consterrorDoc=cheerio.load(`<error></error>`,{xml: true})console.log(errorDoc.root().prop('outerHTML'));// ^^^ First red flag as I'd expect it to return the <error /> elementerrorDoc.root().append(`<message>yooo</message>`);console.log(errorDoc.xml());// '<error/><message>yoo</message>'
The text was updated successfully, but these errors were encountered:
@doge247 This is because root() does not work as you would expect in XML mode. Fix: Get directly the element you want to change-it is actually the element-and then apply append() or prepend() on it.
It seems that cheerio cannot see the root element I've supplied and isn't wrapping the new element into the root as a result of that
And with
.append()
The text was updated successfully, but these errors were encountered: