Skip to content

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 ​

xmlAttrGet an attribute from an element by its non-qualified local name
xmlAttrsGet list of all an elements attributes
xmlElemFind an element by its non-qualified local name
xmlElemsGet the children elements
xmlNameGet the unqualified local name of an element or attribute
xmlNsGet the namespace URI of an element or attribute
xmlPrefixGet the namespace prefix of an element or attribute
xmlQnameGet the qualified local name of an element or attribute which includes both its prefix and unqualified name
xmlReadParse an XML document from an I/O handle and return root element
xmlValIf 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  >>  null

meta ​

deffunc:xmlAttr
isfunc
liblib:xml
namexmlAttr

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon 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 ​

deffunc:xmlAttrs
isfunc
liblib:xml
namexmlAttrs

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon 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 ​

deffunc:xmlElem
isfunc
liblib:xml
namexmlElem

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon 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 ​

deffunc:xmlElems
isfunc
liblib:xml
namexmlElems

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:xmlName ​

xmlName(node) ​

Get the unqualified local name of an element or attribute:

<foo>    >>  "foo"
<x:foo>  >>  "foo"

meta ​

deffunc:xmlName
isfunc
liblib:xml
namexmlName

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon 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 ​

deffunc:xmlNs
isfunc
liblib:xml
namexmlNs

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon 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 ​

deffunc:xmlPrefix
isfunc
liblib:xml
namexmlPrefix

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon 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 ​

deffunc:xmlQname
isfunc
liblib:xml
namexmlQname

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon 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✓
deffunc:xmlRead
isfunc
liblib:xml
namexmlRead

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon 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  >>  null

meta ​

deffunc:xmlVal
isfunc
liblib:xml
namexmlVal

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function