public interface NamespaceContext
只读XML命名空间上下文处理的接口。
一个XML命名空间具有属性:
XMLConstants.XMLNS_ATTRIBUTE
属性的名称的一部分(“xmlns”)在命名空间声明例如:<element xmlns:prefix="http://Namespace-name-URI">
所有的get*(*)
方法操作在当前命名空间URI前缀范围和分辨率。
注意一个命名空间URI可以绑定到当前范围内倍数前缀。这可以发生在多个XMLConstants.XMLNS_ATTRIBUTE
(“xmlns”)命名空间声明出现在相同的起始标签和引用同一个命名空间URI。e.g.
<元xmlns:prefix1 =“http: 名空间uri”xmlns:prefix2="“http:/" 名空间uri”>元xmlns:prefix1>这也可以发生在同一命名空间URI用于多
XMLConstants.XMLNS_ATTRIBUTE
(“xmlns”)命名空间声明的逻辑父元素层次。例如
<母xmlns:prefix1 =“http: 名空间uri”> <孩子xmlns:prefix2 =“http: 名空间uri”> …< /孩子>< /母> 孩子xmlns:prefix2> 母xmlns:prefix1>
前缀只能绑定到当前范围内的单一的命名空间URI。
String getNamespaceURI(String prefix)
得到的命名空间URI绑定到当前范围内的前缀。
当请求一个命名空间URI的前缀,下表列出了所有可能的值返回命名空间URI前缀值:
getNamespaceURI(prefix) return value for specified prefixes |
|
prefix parameter | Namespace URI return value |
DEFAULT_NS_PREFIX ("") |
default Namespace URI in the current scope or when there is no default Namespace URI in the current scope |
bound prefix | Namespace URI bound to prefix in current scope |
unbound prefix | |
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/") |
null |
IllegalArgumentException is thrown |
prefix
前缀查找
IllegalArgumentException
当
prefix
是
null
String getPrefix(String namespaceURI)
获得前缀绑定命名空间URI的电流范围。
让所有前缀绑定到当前范围内的命名空间URI使用getPrefixes(String namespaceURI)
。
当请求一个前缀的命名空间URI,下表描述返回的前缀值的所有命名空间URI值:
getPrefix(namespaceURI) 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 URI | null |
XMLConstants.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") |
null |
IllegalArgumentException is thrown |
namespaceURI
- URI命名空间来查找
IllegalArgumentException
当
namespaceURI
是
null
Iterator getPrefixes(String namespaceURI)
得到所有前缀绑定到当前范围内的命名空间URI。
在字符串的元素的迭代器是任意的,依赖于实现的回来,秩序。
Iterator
是不可修改的。例如,remove()
方法将抛出UnsupportedOperationException
。
当请求前缀的命名空间URI,下面描述的所有命名空间URI前缀值返回值:
getPrefixes(namespaceURI) return value for specified Namespace URIs |
|
---|---|
Namespace URI parameter | prefixes value returned |
bound Namespace URI, including the <default Namespace URI> | Iterator over prefixes bound to Namespace URI in the current scope in an arbitrary, implementation dependent, order |
unbound Namespace URI | empty Iterator |
XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace") |
Iterator with one element set to XMLConstants.XML_NS_PREFIX ("xml") |
XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/") |
Iterator with one element set to XMLConstants.XMLNS_ATTRIBUTE ("xmlns") |
null |
IllegalArgumentException is thrown |
namespaceURI
- URI命名空间来查找
Iterator
IllegalArgumentException
当
namespaceURI
是
null
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.