Cross Reference: /yui3/src/datatype/docs/datatype-xmlformat.mustache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<style scoped>
/* custom styles for this example */
#demo .output {margin-bottom:1em; padding:10px; border:1px solid #D9D9D9;}
</style>
<div class="intro">
<p>The XML module of the DataType Utility allows you to take an XML document and convert it to a string.</p>
</div>
<div class="example yui3-skin-sam">
{{>datatype-xmlformat-source}}
</div>
<p>To output an XML document as a string, simply call the <code>format()</code> function of the DataType.XML class:</p>
```
YUI().use("datatype-xml", function(Y) {
var xmlString =
'<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>';
var myXMLDoc = Y.DataType.XML.parse(xmlString);
alert(Y.DataType.XML.format(myXMLDoc));
});
```