The XML Parser.
{ processingInstructions : List ProcessingInstruction
, docType : Maybe DocType
, root : Node
}
This represents the entire XML structure.
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<!DOCTYPE root SYSTEM "foo.xml">
<root><foo/></root>
{ name : String
, value : String
}
Processing Instruction such as <?xml-stylesheet type="text/xsl" href="style.xsl"?>
.
The example above is parsed as { name = "xml-stylesheet", value = "type=\"text/xsl\" href=\"style.xsl\"" }
.
The value (presudo attributes) should be parsed by application.
{ rootElementName : String
, definition : DocTypeDefinition
}
Doc Type Decralation starting with "<!DOCTYPE".
This contains root element name and rest of details as DocTypeDefinition
.
DTD (Doc Type Definition)
<!DOCTYPE root PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE root SYSTEM "foo.xml">
<!DOCTYPE root [ <!ELEMENT ...> ]>
Node is either a element such as <a name="value">foo</a>
or text such as foo
.
{ name : String
, value : String
}
Attribute such as name="value"
parse : String -> Result (List DeadEnd) Xml
Parse XML string.
<?xml ... ?>
and <!DOCTYPE ... >
is optional so you don't need to ensure them.
> import XmlParser
> XmlParser.parse """<a name="value">foo</a>"""
Ok { processingInstructions = [], docType = Nothing, root = Element "a" ([{ name = "name", value = "value" }]) ([Text "foo"]) }
format : Xml -> String
Convert Xml into String.
This function does NOT insert line breaks or indents for readability.