开发者

check namespace for a node

How to check if namespace exists or not for an element ?开发者_Python百科


How to check if namespace exists or not for an element ?

This question isn't quite clear. In XML (+namespaces) every node has at least two namespaces -- with reserved prefixes "xml" and "xmlns")

I interpret the question to mean:

How to check if a node is in a namespace.

Solution:

not(namespace-uri() = "")

this expression is true() exactly when the current node is in a namespace and false() otherwise.


A namespace always exists - it might be the default one, but it will exist.


Properly speaking, a QName is a tuple (namespace URI, local name, prefix).

For node types other than elements and attributes, namespace URI and prefix are empty.

For an element under a no null (or empty) default namespace URI, only prefix is empty.

All attributes with empty prefix have empty namespace URI.

Each item can be selected with these expressions:

namespace-uri($node)

local-name($node)

substring-before(name($node),':')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜