Saxon.Api

 

 

Saxon.Api

Class QName


public class QName

The QName class represents an instance of xs:QName, as defined in the XPath 2.0 data model. Internally, it has three components, a namespace URI, a local name, and a prefix. The prefix is intended to be used only when converting the value back to a string.

Note that a QName is not itself an XdmItem in this model; however it can be converted to an XdmAtomicValue.

Field Summary

static QName XDT_UNTYPED_ATOMIC

QName constant for the name xs:untypedAtomic (for backwards compatibility)

static QName XS_ANYURI

QName constant for the name xs:anyURI

static QName XS_BOOLEAN

QName constant for the name xs:boolean

static QName XS_DECIMAL

QName constant for the name xs:decimal

static QName XS_DOUBLE

QName constant for the name xs:double

static QName XS_FLOAT

QName constant for the name xs:float

static QName XS_INTEGER

QName constant for the name xs:integer

static QName XS_QNAME

QName constant for the name xs:QName

static QName XS_STRING

QName constant for the name xs:string

static QName XS_UNTYPED_ATOMIC

QName constant for the name xs:untypedAtomic

 

Constructor Summary

QName (string local)

Construct a QName representing a name in no namespace

QName (string uri, string lexical)

Construct a QName using a namespace URI and a lexical representation. The lexical representation may be a local name on its own, or it may be in the form prefix:local-name

QName (string prefix, string uri, string local)

Construct a QName using a namespace prefix, a namespace URI, and a local name (in that order).

QName (string lexicalQName, XdmNode element)

Construct a QName from a lexical QName, supplying an element node whose in-scope namespaces are to be used to resolve any prefix contained in the QName.

QName (XmlQualifiedName qualifiedName)

Construct a QName from an XmlQualifiedName (as defined in the System.Xml package).

 

Property Summary

 string ClarkName

Get the expanded name, as a string using the notation devised by James Clark. If the name is in a namespace, the resulting string takes the form {uri}local. Otherwise, the value is the local part of the name.

 string EQName

Get the expanded name in EQName format, that is Q{uri}local. A no namespace name is returned as Q{}local.

 string LocalName

Get the local part of the QName

 string Prefix

Get the prefix of the QName. This plays no role in operations such as comparison of QNames for equality, but is retained (as specified in XPath) so that a string representation can be reconstructed.

 string Uri

Get the namespace URI of the QName. Returns "" (the zero-length string) if the QName is not in a namespace.

 

Method Summary

 bool Equals(object other)

Test whether two QNames are equal. This supports the semantics of equality, which considers only the namespace URI and local name, and not the prefix.

static QName FromClarkName(string expandedName)

Factory method to construct a QName from a string containing the expanded QName in Clark notation, that is, {uri}local

static QName FromEQName(string expandedName)

Factory method to construct a QName from a string containing the expanded QName in EQName notation, that is, Q{uri}local

 int GetHashCode()

Get a hash code for the QName, to support equality matching. This supports the semantics of equality, which considers only the namespace URI and local name, and not the prefix.

 bool IsValid(Processor processor)

Validate the QName against the XML 1.0 or XML 1.1 rules for valid names.

 bool IsValid()

Validate the QName against the XML rules for valid names.

 void Register(Processor processor)

Register a QName with the Processor. This makes comparison faster when the QName is compared with others that are also registered with the Processor. Depreacted method.

 string ToString()

Convert the value to a string. The resulting string is the lexical form of the QName, using the original prefix if there was one.

 XmlQualifiedName ToXmlQualifiedName()

Convert the value to an XmlQualifiedName (as defined in the System.Xml package)

 

Field Detail

XDT_UNTYPED_ATOMIC

public static readonly QName XDT_UNTYPED_ATOMIC

QName constant for the name xs:untypedAtomic (for backwards compatibility)

XS_ANYURI

public static readonly QName XS_ANYURI

QName constant for the name xs:anyURI

XS_BOOLEAN

public static readonly QName XS_BOOLEAN

QName constant for the name xs:boolean

XS_DECIMAL

public static readonly QName XS_DECIMAL

QName constant for the name xs:decimal

XS_DOUBLE

public static readonly QName XS_DOUBLE

QName constant for the name xs:double

XS_FLOAT

public static readonly QName XS_FLOAT

QName constant for the name xs:float

XS_INTEGER

public static readonly QName XS_INTEGER

QName constant for the name xs:integer

XS_QNAME

public static readonly QName XS_QNAME

QName constant for the name xs:QName

XS_STRING

public static readonly QName XS_STRING

QName constant for the name xs:string

XS_UNTYPED_ATOMIC

public static readonly QName XS_UNTYPED_ATOMIC

QName constant for the name xs:untypedAtomic

Constructor Detail

QName

public QName(string local)

Construct a QName representing a name in no namespace

This constructor does not check that the components of the QName are lexically valid.

Parameters:

local - The local part of the name

QName

public QName(string uri,
             string lexical)

Construct a QName using a namespace URI and a lexical representation. The lexical representation may be a local name on its own, or it may be in the form prefix:local-name

This constructor does not check that the components of the QName are lexically valid.

Parameters:

uri - The namespace URI. Use either the string "" or null for names that are not in any namespace.
lexical - Either the local part of the name, or the prefix and local part in the format prefix:local

QName

public QName(string prefix,
             string uri,
             string local)

Construct a QName using a namespace prefix, a namespace URI, and a local name (in that order).

This constructor does not check that the components of the QName are lexically valid.

Parameters:

prefix - The prefix of the name. Use either the string "" or null for names that have no prefix (that is, they are in the default namespace)
uri - The namespace URI. Use either the string "" or null for names that are not in any namespace.
local - The local part of the name

QName

public QName(string lexicalQName,
             XdmNode element)

Construct a QName from a lexical QName, supplying an element node whose in-scope namespaces are to be used to resolve any prefix contained in the QName.

This constructor checks that the components of the QName are lexically valid.

If the lexical QName has no prefix, the name is considered to be in the default namespace, as defined by xmlns="...".

Parameters:

lexicalQName - The lexical QName, in the form prefix:local or simply local.
element - The element node whose in-scope namespaces are to be used to resolve the prefix part of the lexical QName.

Throws:

ArgumentException - If the prefix of the lexical QName is not in scope
ArgumentException - If the lexical QName is invalid (for example, if it contains invalid characters)

QName

public QName(XmlQualifiedName qualifiedName)

Construct a QName from an XmlQualifiedName (as defined in the System.Xml package).

Note that an XmlQualifiedName does not contain any prefix, so the result will always have a prefix of ""

Parameters:

qualifiedName - The XmlQualifiedName

Property Detail

ClarkName

public string ClarkName {get; }

Get the expanded name, as a string using the notation devised by James Clark. If the name is in a namespace, the resulting string takes the form {uri}local. Otherwise, the value is the local part of the name.

EQName

public string EQName {get; }

Get the expanded name in EQName format, that is Q{uri}local. A no namespace name is returned as Q{}local.

LocalName

public string LocalName {get; }

Get the local part of the QName

Prefix

public string Prefix {get; }

Get the prefix of the QName. This plays no role in operations such as comparison of QNames for equality, but is retained (as specified in XPath) so that a string representation can be reconstructed.

Returns the zero-length string in the case of a QName that has no prefix.

Uri

public string Uri {get; }

Get the namespace URI of the QName. Returns "" (the zero-length string) if the QName is not in a namespace.

Method Detail

Equals

public override bool Equals(object other)

Test whether two QNames are equal. This supports the semantics of equality, which considers only the namespace URI and local name, and not the prefix.

Parameters:

other - The value to be compared with this QName. If this value is not a QName, the result is always false. Otherwise, it is true if the namespace URI and local name both match.

FromClarkName

public static QName FromClarkName(string expandedName)

Factory method to construct a QName from a string containing the expanded QName in Clark notation, that is, {uri}local

The prefix part of the QName will be set to an empty string.

Parameters:

expandedName - The URI in Clark notation: {uri}local if the name is in a namespace, or simply local if not.

FromEQName

public static QName FromEQName(string expandedName)

Factory method to construct a QName from a string containing the expanded QName in EQName notation, that is, Q{uri}local

The prefix part of the QName will be set to an empty string.

Parameters:

expandedName - The QName in EQName notation: Q{uri}local. For a name in no namespace, either of the forms Q{}local or simply local are accepted.

Returns:

the QName corresponding to the supplied name in EQName notation. This will always have an empty prefix.

GetHashCode

public override int GetHashCode()

Get a hash code for the QName, to support equality matching. This supports the semantics of equality, which considers only the namespace URI and local name, and not the prefix.

The algorithm for allocating a hash code does not depend on registering the QName with the Processor.

IsValid

public bool IsValid(Processor processor)

Validate the QName against the XML 1.0 or XML 1.1 rules for valid names.

Parameters:

processor - This argument is no longer used (at one time it was used to establish whether XML 1.0 or XML 1.1 rules should be used for validation, but the two versions of the XML specification have since been aligned).

Returns:

true if the name is valid, false if not

IsValid

public bool IsValid()

Validate the QName against the XML rules for valid names.

Returns:

true if the name is valid, false if not

Register

public void Register(Processor processor)

Register a QName with the Processor. This makes comparison faster when the QName is compared with others that are also registered with the Processor. Depreacted method.

A given QName object can only be registered with one Processor.

Parameters:

processor - The Processor in which the name is to be registered.

ToString

public override string ToString()

Convert the value to a string. The resulting string is the lexical form of the QName, using the original prefix if there was one.

ToXmlQualifiedName

public XmlQualifiedName ToXmlQualifiedName()

Convert the value to an XmlQualifiedName (as defined in the System.Xml package)

Note that this loses the prefix.