Namespaces
Names are stored as written; their namespaces (Namespaces in XML 1.0) are resolved on demand, nothing is stored and parsing is unchanged. The namespace of a tag is declared by the nearest xmlns:prefix attribute (xmlns for an unprefixed name) on the tag or on its ancestors.
f90
ids = coupled%find_all(name='{https://example.org/thermal}dt') ! Clark notation: {namespace}local name
do t=1, coupled%tags_number()
print '(A)', coupled%name(t)//' -> prefix "'//coupled%prefix(t)//'", local "'//coupled%local_name(t)// &
'", namespace "'//coupled%namespace(t)//'"'
enddo| Method | Returns |
|---|---|
prefix(id) | the name prefix, '' if none |
local_name(id) | the name without prefix |
namespace(id) | the namespace URI, '' for no namespace or an undeclared prefix |
The xml prefix is bound to http://www.w3.org/XML/1998/namespace; xmlns="" undeclares the default namespace. Since a prefix cannot be declared empty, prefix(id)/='' with namespace(id)=='' means an undeclared prefix (not reported by parse).
Queries
f90
print '(A)', 'thermal dt: '//coupled%content(id=ids(1))
t = coupled%find(path='f:coupled/f:case/f:dt', namespaces='xmlns:f="https://example.org/flow"') ! your own prefixes
print '(A)', 'flow dt: '//coupled%content(id=t)
t = coupled%find(name='m:conductivity', namespaces='xmlns:m="https://example.org/materials"')
print '(A)', 'k: '//coupled%content(id=t)
print '(A,I0)', 'literal "dt" matches: ', size(coupled%find_all(name='dt')) ! names without a map: literalName in find/find_all (and each path segment) | Matches |
|---|---|
p:local, local | tags with this exact name (prefix included), whatever their namespace |
{uri}local | tags with local name local in namespace uri, whatever their prefix; {}local: in no namespace |
p:local with namespaces= | tags with local name local in the namespace that namespaces declares for p (the file's prefixes do not matter); an undeclared prefix matches nothing |
local with namespaces= | tags with local name local in the default namespace of namespaces (xmlns="uri"), in no namespace if it has none |
A / inside braces is not a path separator, so {uri} may hold a URL. Attribute names are always matched literally.
Next: Regular expressions.