-
public interface NamespaceContext用于只读XML命名空间上下文处理的接口。XML命名空间具有以下属性:
- 名称空间URI:名称空间名称,表示为绑定前缀的URI
- 前缀:语法上,这是命名空间声明中
XMLConstants.XMLNS_ATTRIBUTE(“xmlns”)之后的属性名称的一部分
示例:
<element xmlns:prefix="http://Namespace-name-URI">所有
get*(*)方法都在名称空间URI和前缀解析的当前范围内运行。请注意,名称空间URI可以绑定到当前作用域中的多个前缀。 当多个
XMLConstants.XMLNS_ATTRIBUTE(“xmlns”)命名空间声明出现在同一个Start-Tag中并引用相同的Namespace URI时,就会发生这种情况。 例如当在逻辑父元素层次结构中的多个<element xmlns:prefix1="http://Namespace-name-URI" xmlns:prefix2="http://Namespace-name-URI">XMLConstants.XMLNS_ATTRIBUTE(“xmlns”)命名空间声明中使用相同的名称空间URI时,也会发生这种情况。 例如
<parent xmlns:prefix1="http://Namespace-name-URI"> <child xmlns:prefix2="http://Namespace-name-URI"> ... </child> </parent>前缀只能绑定到当前作用域中的单个名称空间URI。
-
-
方法详细信息
-
getNamespaceURI
String getNamespaceURI(String prefix)
获取命名空间URI绑定到当前范围中的前缀。通过前缀请求名称空间URI时,下表描述了所有可能前缀值的返回名称空间URI值:
Return value for specified prefixes prefix parameter Namespace URI return valueDEFAULT_NS_PREFIX("") default Namespace URI in the current scope orwhen there is no default Namespace URI in the current scope bound prefix Namespace URI bound to prefix in current scope unbound prefixXMLConstants.NULL_NS_URI("")XMLConstants.NULL_NS_URI("")XMLConstants.XML_NS_PREFIX("xml")XMLConstants.XML_NS_URI("http://www.w3.org/XML/1998/namespace")XMLConstants.XMLNS_ATTRIBUTE("xmlns")XMLConstants.XMLNS_ATTRIBUTE_NS_URI("http://www.w3.org/2000/xmlns/")nullIllegalArgumentExceptionis thrown- 参数
-
prefix- 要查找的前缀 - 结果
- 命名空间URI绑定到当前范围中的前缀
- 异常
-
IllegalArgumentException- 当prefix是null
-
getPrefix
String getPrefix(String namespaceURI)
获取当前作用域中名称空间URI的前缀绑定。要获取绑定到当前作用域中的名称空间URI的所有前缀,请使用
getPrefixes(String namespaceURI)。通过名称空间URI请求前缀时,下表描述了所有名称空间URI值的返回前缀值:
Return value for specified Namespace URIs Namespace URI parameter prefix value returned<default Namespace URI>XMLConstants.DEFAULT_NS_PREFIX("") bound Namespace URI prefix bound to Namespace URI in the current scope, if multiple prefixes are bound to the Namespace URI in the current scope, a single arbitrary prefix, whose choice is implementation dependent, is returned unbound Namespace URInullXMLConstants.XML_NS_URI("http://www.w3.org/XML/1998/namespace")XMLConstants.XML_NS_PREFIX("xml")XMLConstants.XMLNS_ATTRIBUTE_NS_URI("http://www.w3.org/2000/xmlns/")XMLConstants.XMLNS_ATTRIBUTE("xmlns")nullIllegalArgumentExceptionis thrown- 参数
-
namespaceURI- 要查找的命名空间的URI - 结果
- 在当前上下文中绑定到名称空间URI的前缀
- 异常
-
IllegalArgumentException- 当namespaceURI是null
-
getPrefixes
Iterator<String> getPrefixes(String namespaceURI)
获取绑定到当前作用域中的Namespace URI的所有前缀。字符串元素的迭代器以任意依赖于实现的顺序返回。
Iterator无法修改。 例如,remove()方法将抛出UnsupportedOperationException。通过Namespace URI请求前缀时,下表描述了所有Namespace URI值的返回前缀值:
Return value for specified Namespace URIs Namespace URI parameter prefixes value returned bound Namespace URI, including the<default Namespace URI>Iteratorover prefixes bound to Namespace URI in the current scope in an arbitrary, implementation dependent, order unbound Namespace URI emptyIteratorXMLConstants.XML_NS_URI("http://www.w3.org/XML/1998/namespace")Iteratorwith one element set toXMLConstants.XML_NS_PREFIX("xml")XMLConstants.XMLNS_ATTRIBUTE_NS_URI("http://www.w3.org/2000/xmlns/")Iteratorwith one element set toXMLConstants.XMLNS_ATTRIBUTE("xmlns")nullIllegalArgumentExceptionis thrown- 参数
-
namespaceURI- 要查找的命名空间的URI - 结果
-
Iterator用于绑定到当前作用域中的Namespace URI的所有前缀 - 异常
-
IllegalArgumentException- 当namespaceURI是null
-
-