次の方法で共有


NamespaceSupport.DeclarePrefix(String, String) Method

Definition

Declare a Namespace prefix.

[Android.Runtime.Register("declarePrefix", "(Ljava/lang/String;Ljava/lang/String;)Z", "GetDeclarePrefix_Ljava_lang_String_Ljava_lang_String_Handler")]
public virtual bool DeclarePrefix (string? prefix, string? uri);
[<Android.Runtime.Register("declarePrefix", "(Ljava/lang/String;Ljava/lang/String;)Z", "GetDeclarePrefix_Ljava_lang_String_Ljava_lang_String_Handler")>]
abstract member DeclarePrefix : string * string -> bool
override this.DeclarePrefix : string * string -> bool

Parameters

prefix
String

The prefix to declare, or the empty string to indicate the default element namespace. This may never have the value "xml" or "xmlns".

uri
String

The Namespace URI to associate with the prefix.

Returns

true if the prefix was legal, false otherwise

Attributes

Remarks

Declare a Namespace prefix. All prefixes must be declared before they are referenced. For example, a SAX driver (parser) would scan an element's attributes in two passes: first for namespace declarations, then a second pass using #processName processName() to interpret prefixes against (potentially redefined) prefixes.

This method declares a prefix in the current Namespace context; the prefix will remain in force until this context is popped, unless it is shadowed in a descendant context.

To declare the default element Namespace, use the empty string as the prefix.

Note that you must <em>not</em> declare a prefix after you've pushed and popped another Namespace context, or treated the declarations phase as complete by processing a prefixed name.

Note that there is an asymmetry in this library: #getPrefix getPrefix will not return the "" prefix, even if you have declared a default element namespace. To check for a default namespace, you have to look it up explicitly using #getURI getURI. This asymmetry exists to make it easier to look up prefixes for attribute names, where the default prefix is not allowed.

Java documentation for org.xml.sax.helpers.NamespaceSupport.declarePrefix(java.lang.String, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also