XML Module
Examples
Reading an XML document
// Read an example document and extract information from it.
open XML;
open Seq;
let data = `<items>
<item id="001">
<name>Apple (Cox Pomona)</name>
</item>
<item id="002">
<name>Apple (Ingrid Marie)</name>
</item>
<item id="003">
<name>Orange (Valencia)</name>
</item>
</items>`;
// Use the 'parse' function to turn the text into an XML DOM document.
let doc = parse(data);
// For each child element of the document root (i.e. for each <item> element),
// map that into a record containing the value of the "id" attribute
// and the value of the <name> child element.
return doc.root
.getChildren()
.map(e => {
id: e.getNamedAttribute("id").value,
name: e.getNamedChild("name").value
});
// The resulting FlowScript sequence will look like this:
// [
// {
// id: "001",
// name: "Apple (Cox Pomona)"
// },
// {
// id: "002",
// name: "Apple (Ingrid Marie)"
// },
// {
// id: "003",
// name: "Orange (Valencia)"
// }
// ] Creating an XML document
Types
QName
QNameAttribute
AttributeElement
ElementDocument
DocumentNode
NodeFunctions
Functions for reading XML
parse(value: text) -> Document
parse(value: text) -> DocumentgetDescendants(self el: Element) -> Element*
getDescendants(self el: Element) -> Element*getNamedChildren(self el: Element?, localName: text) -> Element*
getNamedChildren(self el: Element?, localName: text) -> Element*getNamedChild(self el: Element?, localName: text) -> Element?
getNamedChild(self el: Element?, localName: text) -> Element?getNamedAttribute(self el: Element?, localName: text) -> Attribute?
getNamedAttribute(self el: Element?, localName: text) -> Attribute?getChildren(self el: Element?) -> Element*
getChildren(self el: Element?) -> Element*Functions for creating XML
print(doc: Document) -> text
print(doc: Document) -> textdocument(root: Element) -> Document
document(root: Element) -> Documentelement(name: text | QName, ...contents: Node*) -> Element
element(name: text | QName, ...contents: Node*) -> Elementattribute(name: text | QName, value: text) -> Attribute
attribute(name: text | QName, value: text) -> AttributequalifiedName(namespace: text?, localName: text) -> QName
qualifiedName(namespace: text?, localName: text) -> QNameLast updated
Was this helpful?