module lang::xml::IO
rascal-0.40.16
Usage
import lang::xml::IO;
function readXML
value readXML(loc file, bool fullyQualify=false, bool trackOrigins = false, bool includeEndTags=false, bool ignoreComments=true, bool ignoreWhitespace=true, str charset="UTF-8", bool inferCharset=!(charset?))
value readXML(str contents, loc src = |unknown:///|, bool fullyQualify=false, bool trackOrigins = false, bool includeEndTags=false, bool ignoreComments=true, bool ignoreWhitespace=true)
function writeXMLString
Pretty-print any value as an XML string.
str writeXMLString(value val, str charset="UTF-8", bool outline=false, bool prettyPrint=true, int indentAmount=4, int maxPaddingWidth=30, bool dropOrigins=true)
This function uses JSoup's DOM functionality to yield a syntactically correct XML string.
function writeXMLFile
Pretty-print any value to an XML file.
void writeXMLFile(loc file, value val, str charset="UTF-8", bool outline=false, bool prettyPrint=true, int indentAmount=4, int maxPaddingWidth=30, bool dropOrigins=true)
This function uses JSoup's DOM functionality to yield a syntactically correct (X)HTML file.
Tests
test nestedElementTest
test bool nestedElementTest() {
example = "\<aap\>\<noot\>mies\</noot\>\</aap\>";
val = readXML(example);
return val == "aap"("noot"("mies"));
}
test attributeTest
test bool attributeTest() {
example = "\<aap age=\"1\"\>\</aap\>";
val = readXML(example);
return val == "aap"(age="1");
}
test namespaceTest
test bool namespaceTest() {
example = "\<aap xmlns:ns=\"http://trivial\" ns:age=\"1\" age=\"2\"\>\</aap\>";
val = readXML(example);
return "aap"(\ns-age="1", age="2") := val;
}