<form id="demo">
    <input type="button" id="demo_btn" value="Show XML as a string">
    <div id="demo_output" class="output">&nbsp;</div>
</form>

<script>
YUI().use("node", "datatype-xml", function (Y) {
    Y.on("click", function(e){
        var myXMLDoc = Y.XML.parse("<myroot><item type='foo'><name>Abc</name><rank>1</rank></item><item type='bar'><name>Def</name><rank>2</rank></item><item type='bat'><name>Ghhi</name><rank>3</rank></item></myroot>"),
            output = Y.XML.format(myXMLDoc);

        if(output === "") {
            output += "(Invalid XML document)"
        }
        Y.one("#demo_output").setHTML(output.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"));
    }, "#demo_btn");
});
</script>
