最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I output xml in the console in IE? - Stack Overflow

programmeradmin1浏览0评论

I am trying to inspect an xml file in the console in IE11. In every other browser, all I have to do is add the line console.log(myXML); and it will output the raw xml in the console. However, the same code will output an object representation with all its properties in IE11 and Edge. I just want to see the xml just like it's displayed in all other browsers. How do I acplish this? And why the heck would IE do it differently than other browsers in the first place?

I am trying to inspect an xml file in the console in IE11. In every other browser, all I have to do is add the line console.log(myXML); and it will output the raw xml in the console. However, the same code will output an object representation with all its properties in IE11 and Edge. I just want to see the xml just like it's displayed in all other browsers. How do I acplish this? And why the heck would IE do it differently than other browsers in the first place?

Share Improve this question asked Jul 6, 2017 at 16:14 Guybrush ThreepwoodGuybrush Threepwood 1511 gold badge2 silver badges9 bronze badges 1
  • Try using string formatting: console.log('%s',myXML); – hindmost Commented Jul 6, 2017 at 16:20
Add a ment  | 

2 Answers 2

Reset to default 5

Use the dirxml method.

Per the official documentation found here: https://msdn.microsoft./en-us/library/dn265067(v=vs.85).aspx

Dirxml: Logs an XML node object to the console.

var parser = new DOMParser(); 
var xml = parser.parseFromString("<books isbn=\"1111\"><book><title>Hello world!</title></book></books>", "application/xml");
console.dirxml(xml);

Have you tried using the XMLSerializer?

var myXMLstring = new XMLSerializer().serializeToString(myXml)
console.log(myXMLstring)
发布评论

评论列表(0)

  1. 暂无评论