XML document, element, attribute, parser-result, and serialization helpers.


Core schemas


XMLParserResult


Parser model


parseStringToXML (source -- result)

Parses one accepted UTF-8 source into XMLParserResult.


saveXMLToString (xml -- string)

Serializes one XMLDocument to a formatted String.


Examples

Successful parse and stored counts

"Xml"     use
"control" use

{} () {} [
  result: "<root a=\"b\"><child/></root>" parseStringToXML;
  @result.@success TRUE same printStack _:;
  @result.@finished TRUE same printStack _:;
  @result.@xml.@root.@attributes.size 1 same printStack _:;
  @result.@xml.@root.children.size 1 same printStack _:;
] "main" exportFunction

Expected Output During Compilation

TRUE
TRUE
TRUE
TRUE

Trailing input, duplicate attribute, discarded whitespace-only child data, and unsupported reference

"Xml"     use
"control" use

{} () {} [
  trailing: "<root/>x" parseStringToXML;
  @trailing.@success TRUE same printStack _:;
  @trailing.@finished FALSE same printStack _:;

  duplicate: "<root a=\"1\" a=\"2\"/>" parseStringToXML;
  @duplicate.@success FALSE same printStack _:;

  spaces: "<root>   </root>" parseStringToXML;
  @spaces.@xml.@root.children.size 0 same printStack _:;

  apos: "<root>'</root>" parseStringToXML;
  @apos.@success FALSE same printStack _:;
] "main" exportFunction

Expected Output During Compilation

TRUE
TRUE
TRUE
TRUE
TRUE

Runtime example

"String"  use
"Xml"     use
"control" use

{} Int32 {} [
  result: "<root a=\"b\"><child/></root>" parseStringToXML;
  ("success=" result.success LF
    "finished=" result.finished LF
    "attrs=" result.xml.root.attributes.size LF
    "children=" result.xml.root.children.size LF) printList
  0
] "main" exportFunction

Expected Output

success=TRUE
finished=TRUE
attrs=1
children=1

See also