📅  最后修改于: 2023-12-03 15:33:08.439000             🧑  作者: Mango
Node.js console.dirxml()方法输出指定对象的XML或HTML元素表示形式。
console.dirxml(obj)
以下代码演示了使用console.dirxml()方法输出HTML元素的示例:
const fs = require('fs');
const xml = `
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J.K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>`;
const html = fs.readFileSync('./index.html', 'utf8');
console.dirxml(xml);
console.dirxml(html);
输出结果如下所示:
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J.K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
<body>
<header>
<h1>Hello World!</h1>
</header>
<main>
<p>Welcome to my website!</p>
</main>
<footer>
<small>© 2021 - Node.js Example</small>
</footer>
</body>