Navigation
Synopsis Convert a DOM instance to a pretty printed XML string.
Function str xmlPretty(Node x)
Usage import lang::xml::DOM;
Examples Read the sample note file, parse it, construct a DOM instance, and convert it to a string:
rascal>import IO;
ok
rascal>import lang::xml::DOM;
ok
rascal>F = readFile(|courses:///Rascal/Libraries/lang/xml/note.xml|);
str: "\<note\>\n\<to\>Jurgen\</to\>\n\<to\>Tijs\</to\>\n\<from\>Paul\</from\>\n\<date\>2012-04-01\</date\>\n\<heading font=\"bold\"\>Reminder\</heading\>\n\<body\>Don\'t forget to run the Rascal tests!\</body\>\n\</note\>"
rascal>println(F);
<note>
<to>Jurgen</to>
<to>Tijs</to>
<from>Paul</from>
<date>2012-04-01</date>
<heading font="bold">Reminder</heading>
<body>Don't forget to run the Rascal tests!</body>
</note>
ok
rascal>S = xmlPretty(parseXMLDOM(F));
str: "\<?xml version=\"1.0\" encoding=\"UTF-8\"?\>\r\n\<note\>\r\n  \<to\>Jurgen\</to\>\r\n  \<to\>Tijs\</to\>\r\n  \<from\>Paul\</from\>\r\n  \<date\>2012-04-01\</date\>\r\n  \<heading font=\"bold\"\>Reminder\</heading\>\r\n  \<body\>Don\'t forget to run the Rascal tests!\</body\>\r\n\</note\>\r\n\r\n"
rascal>println(S);
<?xml version="1.0" encoding="UTF-8"?>
<note>
  <to>Jurgen</to>
  <to>Tijs</to>
  <from>Paul</from>
  <date>2012-04-01</date>
  <heading font="bold">Reminder</heading>
  <body>Don't forget to run the Rascal tests!</body>
</note>


ok
The output S of xmlPretty is a pretty printed version of the original source file F. Observe that the elements inside <note> ... </note> are indented.
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.