外观
lib-xml 库参考
原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793717823/FIN+5.3.1+lib-xml 中文整理基于 FIN 5.3.1
导读: XML 函数库
以下为 API 参考,保留英文以便对照源码;目录已列出(英文标题便于检索);概述已尽量中译。
目录(导读)
- lib
- meta
- funcs
- def
- xmlAttr(elem, name, checked: true)
- xmlAttrs(elem)
- xmlElem(elem, name, checked: true)
- xmlElems(elem)
- xmlName(node)
- xmlNs(node)
- xmlPrefix(node)
- xmlQname(node)
- xmlRead(handle)
- xmlVal(node)
概述(中译)
XML 函数库
API 正文(英文)
funcs
| xmlAttr | Get an attribute from an element by its non-qualified local name |
| xmlAttrs | Get list of all an elements attributes |
| xmlElem | Find an element by its non-qualified local name |
| xmlElems | Get the children elements |
| xmlName | Get the unqualified local name of an element or attribute |
| xmlNs | Get the namespace URI of an element or attribute |
| xmlPrefix | Get the namespace prefix of an element or attribute |
| xmlQname | Get the qualified local name of an element or attribute which includes both its prefix and unqualified name |
| xmlRead | Parse an XML document from an I/O handle and return root element |
| xmlVal | If node is an attribute, then return its value string |
def
func:xmlAttr
xmlAttr(elem, name, checked: true)
Get an attribute from an element by its non-qualified local name. If the attribute is not found and checked is false then return null otherwise throw XErr.
Examples:
xmlRead("<x a='v'/>").xmlAttr("a").xmlVal >> "v"
xmlRead("<x/>").xmlAttr("a", false).xmlVal >> nullmeta
| def | func:xmlAttr |
| is | func |
| lib | lib:xml |
| name | xmlAttr |
supertypes
| feature | Feature namespace of definitions formatted as feature:name |
| func | Axon function |
def
func:xmlAttrs
xmlAttrs(elem)
Get list of all an elements attributes.
Example:
attrs: xmlRead("<x a='' b=''/>").xmlAttrs
attrs.map(xmlName) >> ["a", "b"]meta
| def | func:xmlAttrs |
| is | func |
| lib | lib:xml |
| name | xmlAttrs |
supertypes
| feature | Feature namespace of definitions formatted as feature:name |
| func | Axon function |
def
func:xmlElem
xmlElem(elem, name, checked: true)
Find an element by its non-qualified local name. If there are multiple child elements with the name, then the first one is returned. If the element is not found and checked is false then return null otherwise throw XErr.
Example:
xmlRead("<d><a/></d>").xmlElem("a")meta
| def | func:xmlElem |
| is | func |
| lib | lib:xml |
| name | xmlElem |
supertypes
| feature | Feature namespace of definitions formatted as feature:name |
| func | Axon function |
def
func:xmlElems
xmlElems(elem)
Get the children elements. If this element contains text or PI nodes, then they are excluded in the result.
Example:
elems: xmlRead("<d><a/><b/></d>").xmlElems
elems.map(xmlName) >> ["a", "b"]meta
| def | func:xmlElems |
| is | func |
| lib | lib:xml |
| name | xmlElems |
supertypes
| feature | Feature namespace of definitions formatted as feature:name |
| func | Axon function |
def
func:xmlName
xmlName(node)
Get the unqualified local name of an element or attribute:
<foo> >> "foo"
<x:foo> >> "foo"meta
| def | func:xmlName |
| is | func |
| lib | lib:xml |
| name | xmlName |
supertypes
| feature | Feature namespace of definitions formatted as feature:name |
| func | Axon function |
def
func:xmlNs
xmlNs(node)
Get the namespace URI of an element or attribute. If no namespace was specified return null.
Example:
xmlRead("<foo xmlns='bar'/>").xmlNs >> `bar`meta
| def | func:xmlNs |
| is | func |
| lib | lib:xml |
| name | xmlNs |
supertypes
| feature | Feature namespace of definitions formatted as feature:name |
| func | Axon function |
def
func:xmlPrefix
xmlPrefix(node)
Get the namespace prefix of an element or attribute. If node is an element in the default namespace then return "". If no namespace is specified return null.
Examples:
<foo> >> null
<x:foo> >> "x"
<foo xmlns='...'/> >> ""meta
| def | func:xmlPrefix |
| is | func |
| lib | lib:xml |
| name | xmlPrefix |
supertypes
| feature | Feature namespace of definitions formatted as feature:name |
| func | Axon function |
def
func:xmlQname
xmlQname(node)
Get the qualified local name of an element or attribute which includes both its prefix and unqualified name:
<foo> >> "foo"
<x:foo> >> "x:foo"meta
| def | func:xmlQname |
| is | func |
| lib | lib:xml |
| name | xmlQname |
supertypes
| feature | Feature namespace of definitions formatted as feature:name |
| func | Axon function |
def
func:xmlRead
xmlRead(handle)
Parse an XML document from an I/O handle and return root element.
Examples:
xmlRead("<foo/>")
xmlRead(`io/test.xml`)meta
| admin | ✓ |
| def | func:xmlRead |
| is | func |
| lib | lib:xml |
| name | xmlRead |
supertypes
| feature | Feature namespace of definitions formatted as feature:name |
| func | Axon function |
def
func:xmlVal
xmlVal(node)
If node is an attribute, then return its value string. If node is an element return its first text child node, otherwise null. If node is null, then return null.
Examples:
xmlRead("<x/>").xmlVal >> null
xmlRead("<x>hi</x>").xmlVal >> "hi"
xmlRead("<x a='v'/>").xmlAttr("a").xmlVal >> "v"
xmlRead("<x/>").xmlAttr("a", false).xmlVal >> nullmeta
| def | func:xmlVal |
| is | func |
| lib | lib:xml |
| name | xmlVal |
supertypes
| feature | Feature namespace of definitions formatted as feature:name |
| func | Axon function |