XML
System.Xml
[00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ]
1.0.5000.0
2.0.0.0
All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.
System.Object
Encodes and decodes XML names and provides methods for converting
between common language infrastructure (CLI) types and XML Schema Definition
language (XSD) types. When converting data types, the values returned are locale independent.
Element and attribute names or ID values are limited to a
range of XML characters according to the Extensible Markup Language (XML) 1.0
(Second Edition) recommendation, located at
www.w3.org/TR/2000/REC-xml-20001006.html. When names contain invalid characters, they need to be translated into valid XML
names.
Many languages
and applications allow Unicode characters in their names, which are not valid in XML names.
For example, if 'Order Detail' were a column heading in a database, the database
allows the space between the words Order and Detail. However, in XML, the space
between Order and Detail is considered an invalid XML character. Thus, the
space, the invalid character, needs to be converted into an escaped hexadecimal
encoding and can be decoded later.
The and methods are
used to translate invalid
XML names into valid XML names and vice versa.
provides methods that enable the conversion of a
to a
CLI data type and vice-versa. Locale settings
are not taken into account during data conversion.
also provides
methods that convert between XML Schema Definition (XSD) data types (see http://www.w3.org/TR/xmlschema-2/#built-in-datatypes) and their
corresponding common language infrastructure (CLI) data
types. The following table shows the XSD
data types and their corresponding CLI data types.
XSD
data type
CLI
data type
-
hexBinary
A
array
-
base64Binary
A
array
-
Boolean
-
Byte
-
normalizedString
-
Date
-
duration
-
dateTime
-
decimal
-
Double
-
ENTITIES
A array
-
ENTITY
-
Float
-
gMonthDay
-
gDay
-
gYear
-
gYearMonth
-
ID
-
IDREF
-
IDREFS
A
array
-
int
-
integer
-
language
-
long
-
month
-
Name
-
NCName
-
negativeInteger
-
NMTOKEN
-
NMTOKENS
A
array
-
nonNegativeInteger
-
nonPositiveInteger
-
NOTATION
-
positiveInteger
-
short
-
string
-
time
-
timePeriod
-
token
-
unsignedByte
-
unsignedInt
-
unsignedLong
-
unsignedShort
-
anyURI
Constructor
Constructs a new instance of the class.
To be added.
0
1.0.5000.0
2.0.0.0
Method
System.String
A specifying the name to be decoded.
Decodes a name.
A containing the decoded name.
Names are decoded using the following rules:
-
Names are decoded from left to right.
-
Any sequence _xHHHH_ (where HHHH stands for a valid, four
digit hexadecimal UCS-2 code) that has not been previously decoded is
transformed into the corresponding Unicode 2.1 (Unicode 3.0 if supported by
the application) character.
-
No
short forms are recognized. They are passed on without translation. For
example, "_x70_" or "__" are not decoded.
This method does the reverse of the , , and methods.
The following example demonstrates the valid and invalid
character formats for decoding.
using System;
using System.Xml;
public class App {
public static void Main() {
Console.WriteLine( "{0} : {1} : {2}",
// _x0069_ decodes to i
XmlConvert.DecodeName("Order #1_x0069_"),
// missing beginning _
XmlConvert.DecodeName("Order #1x0069_"),
// short form
XmlConvert.DecodeName("Order #1_x69_") );
}
}
The output is
Order #1i : Order #1x0069_ : Order #1_x69_
0
1.0.5000.0
2.0.0.0
Method
System.String
A specifying the name to be encoded.
Converts a name to a valid XML local name.
A containing the XML local name. If is or , is returned.
This method is similar to the method except that it encodes the colon (:) character, which
guarantees that the name can be used as the local name part of a namespace
qualified name.
The following example compares the , , and methods when the name to be encoded is "7:+".
using System;
using System.Xml;
public class App {
public static void Main() {
Console.WriteLine( "LocalName {0}",
XmlConvert.EncodeLocalName("7:+") );
Console.WriteLine( "Name {0}",
XmlConvert.EncodeName("7:+") );
Console.WriteLine( "NmToken {0}",
XmlConvert.EncodeNmToken("7:+") );
}
}
The output is
LocalName _x0037__x003A__x002B_
Name _x0037_:_x002B_
NmToken 7:_x002B_
0
1.0.5000.0
2.0.0.0
Method
System.String
A specifying the name to be encoded.
Converts a
name to a valid XML name.
A containing the XML name. If is or , is returned.
This method translates invalid characters, such as spaces or half-width
Katakana, that need to be mapped to XML names without the support or presence of
schemas. The invalid characters are translated into escaped numeric entity
encodings.
The escape character is '_'. Any XML name character that does not conform to
the W3C Extensible Markup Language (XML) 1.0 specification is escaped as
_xHHHH_. The HHHH string stands for the four-digit hexadecimal UCS-2 code for the
character in most significant bit first order. For example, the name "Order
Details" is encoded as "Order_x0020_Details".
The underscore character does not need to be escaped
unless it is followed by a character sequence that together with the underscore can be misinterpreted as an escape sequence
when decoding the name. No short forms are encoded. For example, the
forms "_x20_" and "__" are not encoded.
This method guarantees the name is valid according to the XML specification.
It allows colons in any position, which means the name might still be invalid according
to the W3C Namespace Specification (www.w3.org/TR/REC-xml-names). To guarantee it is a valid namespace qualified
name use the
method for the prefix and local name
parts and join the result with a colon.
See the method for an example comparing the , , and methods.
0
1.0.5000.0
2.0.0.0
Method
System.String
A specifying the name to be encoded.
Converts
a name to a valid XML name token.
A containing the XML name token. If is or , is
returned.
To be added.
See the method for an example comparing the
, , and methods.
0
1.0.5000.0
2.0.0.0
Method
System.Boolean
The to convert.
Converts a to a equivalent.
The equivalent of
.
This method removes leading and trailing white space. After this trimming, valid strings are "1" and "true", which return
, and "0" and "false", which return .
is a null reference.
does not represent a value.
0
1.0.5000.0
2.0.0.0
Method
System.Byte
The to convert.
Converts a to a equivalent.
The equivalent of
.
This method calls (, |, ).
is a null reference.
is not in the correct format.
represents a number less than or greater than .
0
1.0.5000.0
2.0.0.0
Method
System.Char
The string containing a single character to convert.
Converts a to a equivalent.
The equivalent of
.
This method calls ().
is a null reference.
contains more than one character.
0
1.0.5000.0
2.0.0.0
Method
System.DateTime
The to convert.
Converts a to a equivalent.
The equivalent of .
is required to be in one of the following string formats or
a is thrown.
"yyyy-MM-ddTHH:mm:ss"
"yyyy-MM-ddTHH:mm:ss.f"
"yyyy-MM-ddTHH:mm:ss.ff"
"yyyy-MM-ddTHH:mm:ss.fff"
"yyyy-MM-ddTHH:mm:ss.ffff"
"yyyy-MM-ddTHH:mm:ss.fffff"
"yyyy-MM-ddTHH:mm:ss.ffffff"
"yyyy-MM-ddTHH:mm:ss.fffffff"
"yyyy-MM-ddTHH:mm:ssZ"
"yyyy-MM-ddTHH:mm:ss.fZ"
"yyyy-MM-ddTHH:mm:ss.ffZ"
"yyyy-MM-ddTHH:mm:ss.fffZ"
"yyyy-MM-ddTHH:mm:ss.ffffZ"
"yyyy-MM-ddTHH:mm:ss.fffffZ"
"yyyy-MM-ddTHH:mm:ss.ffffffZ"
"yyyy-MM-ddTHH:mm:ss.fffffffZ"
"yyyy-MM-ddTHH:mm:sszzzzzz"
"yyyy-MM-ddTHH:mm:ss.fzzzzzz"
"yyyy-MM-ddTHH:mm:ss.ffzzzzzz"
"yyyy-MM-ddTHH:mm:ss.fffzzzzzz"
"yyyy-MM-ddTHH:mm:ss.ffffzzzzzz"
"yyyy-MM-ddTHH:mm:ss.fffffzzzzzz"
"yyyy-MM-ddTHH:mm:ss.ffffffzzzzzz"
"yyyy-MM-ddTHH:mm:ss.fffffffzzzzzz"
"HH:mm:ss"
"HH:mm:ss.f"
"HH:mm:ss.ff"
"HH:mm:ss.fff"
"HH:mm:ss.ffff"
"HH:mm:ss.fffff"
"HH:mm:ss.ffffff"
"HH:mm:ss.fffffff"
"HH:mm:ssZ"
"HH:mm:ss.fZ"
"HH:mm:ss.ffZ"
"HH:mm:ss.fffZ"
"HH:mm:ss.ffffZ"
"HH:mm:ss.fffffZ"
"HH:mm:ss.ffffffZ"
"HH:mm:ss.fffffffZ"
"HH:mm:sszzzzzz"
"HH:mm:ss.fzzzzzz"
"HH:mm:ss.ffzzzzzz"
"HH:mm:ss.fffzzzzzz"
"HH:mm:ss.ffffzzzzzz"
"HH:mm:ss.fffffzzzzzz"
"HH:mm:ss.ffffffzzzzzz"
"HH:mm:ss.fffffffzzzzzz"
"yyyy-MM-dd"
"yyyy-MM-ddZ"
"yyyy-MM-ddzzzzzz"
"yyyy-MM"
"yyyy-MMZ"
"yyyy-MMzzzzzz"
"yyyy"
"yyyyZ"
"yyyyzzzzzz"
"--MM-dd"
"--MM-ddZ"
"--MM-ddzzzzzz"
"---dd"
"---ddZ"
"---ddzzzzzz"
"--MM--"
"--MM--Z"
"--MM--zzzzzz"
is a null reference.
is or is not in the correct format.
0
1.0.5000.0
2.0.0.0
System.Obsolete
Method
System.DateTime
The to convert.
A specifying the format used to validate .
To be added.
Converts a to a equivalent.
The equivalent of .
This method calls (, , , |).
Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets.
is a null reference.
or is .
-or-
does not contain a date and time that corresponds to .
0
1.0.5000.0
2.0.0.0
Method
System.DateTime
The to convert.
A array specifying formats used to validate .
To be added.
Converts a to a equivalent.
The equivalent of .
This method calls (, , , |).
This method allows to
be validated against multiple formats.
Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets.
is a null reference.
or an element of is .
-or-
does not contain a date and time that corresponds to any of the elements of .
The following example converts a to a and writes the
result to the console.
using System;
using System.Xml;
public class App {
public static void Main() {
String someDate = "1966-09-19T03:45:11Z";
String[] datetimeFormats = new String[]
{"HH:mm:ss", "yyyy-MM-ddTHH:mm:ssZ"};
DateTime dateTime =
XmlConvert.ToDateTime(someDate, datetimeFormats);
Console.WriteLine( "{0}", dateTime.ToString() );
}
}
The output is
9/18/1966 8:45:11 PM
0
1.0.5000.0
2.0.0.0
Method
System.DateTime
To be added.
To be added.
To be added.
To be added.
To be added.
2.0.0.0
Method
2.0.0.0
System.DateTimeOffset
To be added.
To be added.
To be added.
To be added.
Method
2.0.0.0
System.DateTimeOffset
To be added.
To be added.
To be added.
To be added.
To be added.
Method
2.0.0.0
System.DateTimeOffset
To be added.
To be added.
To be added.
To be added.
To be added.
Method
System.Decimal
The to convert.
Converts a to a equivalent.
The
equivalent of .
This method calls (, |||, ).
is a null reference.
is not in the correct format.
represents a number less than or greater than .
1
ExtendedNumerics
1.0.5000.0
2.0.0.0
Method
System.Double
The to convert.
Converts a to a equivalent.
The
equivalent of .
If is "-INF", this method returns .
If is "INF", this method returns .
Otherwise, this method calls (, ||||, ).
is a null reference.
is not in the correct format.
represents a number less than or greater than .
1
ExtendedNumerics
1.0.5000.0
2.0.0.0
Method
System.Guid
To be added.
To be added.
To be added.
To be added.
1.0.5000.0
2.0.0.0
Method
System.Int16
The to convert.
Converts a to a equivalent.
The
equivalent of .
This method calls (, ||, ).
is a null reference.
is not in the correct format.
represents a number less than or greater than .
0
1.0.5000.0
2.0.0.0
Method
System.Int32
The to convert.
Converts a to a equivalent.
The
equivalent of .
This method calls (, ||, ).
is a null reference.
is not in the correct format.
represents a number less than or greater than .
0
1.0.5000.0
2.0.0.0
Method
System.Int64
The to convert.
Converts a to a equivalent.
The
equivalent of .
This method calls (, ||, ).
is a null reference.
is not in the correct format.
represents a number less than or greater than .
0
1.0.5000.0
2.0.0.0
Method
System.SByte
The to convert.
Converts a to a equivalent.
The equivalent of
.
This member is not CLS-compliant. For a CLS-compliant alternative, use
().
This method calls (, ||, ).
is a null reference.
is not in the correct format.
represents a number less than or greater than .
0
1.0.5000.0
2.0.0.0
System.CLSCompliant(false)
Method
System.Single
The to convert.
Converts a to a equivalent.
The equivalent of
.
If is "-INF", this method returns .
If is "INF", this method returns .
Otherwise, this method calls (, ||||, ).
is a null reference.
is not in the correct format.
represents a number less than or greater than .
1
ExtendedNumerics
1.0.5000.0
2.0.0.0
Method
System.String
The to convert.
Converts a to a .
The "true" or the
"false".
To be added.
0
1.0.5000.0
2.0.0.0
Method
System.String
The to convert.
Converts a to a .
The representation of .
This method calls .ToString(, ).
0
1.0.5000.0
2.0.0.0
Method
System.String
The to convert.
Converts a to a .
The representation of .
This method calls .ToString().
0
1.0.5000.0
2.0.0.0
Method
System.String
The to convert.
Converts a to a .
The representation of .
This method calls (,
"yyyy-MM-ddTHH:mm:ss.fffffffzzzzzz").
0
1.0.5000.0
2.0.0.0
System.Obsolete
Method
2.0.0.0
System.String
To be added.
To be added.
To be added.
To be added.
Method
System.String
The to convert.
Converts a to a .
The representation of .
This method calls .ToString(, ).
1
ExtendedNumerics
1.0.5000.0
2.0.0.0
Method
System.String
The to convert.
Converts a to a .
The representation of .
If is , this method returns "-INF".
If is , this method returns "INF".
Otherwise, this method calls .ToString("R", ).
1
ExtendedNumerics
1.0.5000.0
2.0.0.0
Method
System.String
To be added.
To be added.
To be added.
To be added.
1.0.5000.0
2.0.0.0
Method
System.String
The to convert.
Converts a to a .
The representation of .
This method calls .ToString(, ).
0
1.0.5000.0
2.0.0.0
Method
System.String
The to convert.
Converts a to a .
The representation of .
This method calls .ToString(, ).
0
1.0.5000.0
2.0.0.0
Method
System.String
The to convert.
Converts a to a .
The representation of .
This method calls .ToString(, ).
0
1.0.5000.0
2.0.0.0
Method
System.String
The to convert.
Converts a to a .
The representation of .
This member is not CLS-compliant. For a CLS-compliant alternative, use
().
This method calls .ToString(, ).
0
1.0.5000.0
2.0.0.0
System.CLSCompliant(false)
Method
System.String
The to convert.
Converts a to a .
The representation of .
If is , this method returns "-INF".
If is , this method returns "INF".
Otherwise, this method calls .ToString("R", ).
1
ExtendedNumerics
1.0.5000.0
2.0.0.0
Method
System.String
The to convert.
Converts a to a .
The representation of .
To be added.
The following example converts a to a and writes the result
to the console.
using System;
using System.Xml;
public class App {
public static void Main() {
TimeSpan timeSpan = new TimeSpan(3, 11, 59, 6, 128);
Console.WriteLine( "{0}",
XmlConvert.ToString(timeSpan) );
}
}
The output is
P3DT11H59M6.128S
0
1.0.5000.0
2.0.0.0
Method
System.String
The to convert.
Converts a to a .
The representation of .
This member is not CLS-compliant. For a CLS-compliant
alternative, use ().
This method calls .ToString(, ).
0
1.0.5000.0
2.0.0.0
System.CLSCompliant(false)
Method
System.String
The to convert.
Converts a to a .
The representation of .
This member is not CLS-compliant. For a CLS-compliant alternative, use
().
This method calls .ToString(, ).
0
1.0.5000.0
2.0.0.0
System.CLSCompliant(false)
Method
System.String
The to convert.
Converts a to a .
The representation of .
This member is not CLS-compliant. For a CLS-compliant alternative, use
().
This method calls .ToString(, ).
0
1.0.5000.0
2.0.0.0
System.CLSCompliant(false)
Method
System.String
The to convert.
A specifying the format to apply to . Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets.
To be added.
Converts a to a .
The representation of in the specified format..
This method calls .ToString(, ).
0
1.0.5000.0
2.0.0.0
Method
System.String
To be added.
To be added.
To be added.
To be added.
To be added.
2.0.0.0
Method
2.0.0.0
System.String
To be added.
To be added.
To be added.
To be added.
To be added.
Method
System.TimeSpan
The to convert.
Converts a to a equivalent.
The equivalent of
.
To be added.
is not in the correct format to represent a value.
0
1.0.5000.0
2.0.0.0
Method
System.UInt16
The to convert.
Converts a to a equivalent.
The equivalent of
.
This member is not CLS-compliant. For a CLS-compliant alternative, use
().
This method calls (, ||, ).
is a null reference.
is not in the correct format.
represents a number less than or greater than .
0
1.0.5000.0
2.0.0.0
System.CLSCompliant(false)
Method
System.UInt32
The to convert.
Converts a to a equivalent.
The equivalent of
.
This member is not CLS-compliant. For a CLS-compliant alternative, use
().
This method calls (, ||, ).
is a null reference.
is not in the correct format.
represents a number less than or greater than .
0
1.0.5000.0
2.0.0.0
System.CLSCompliant(false)
Method
System.UInt64
The to convert.
Converts a to a equivalent.
The equivalent of
.
This member is not CLS-compliant. For a CLS-compliant alternative, use
().
This method calls (, ||, ).
is a null reference.
is not in the correct format.
represents a number less than or greater than .
0
1.0.5000.0
2.0.0.0
System.CLSCompliant(false)
Method
System.String
A specifying the name to verify.
Verifies that the name is a valid name as defined in
the W3C Extended Markup Language recommendation (REC-xml-names-19990114).
The , if it is a valid XML name.
To be added.
is or .
is not a valid XML name.
0
1.0.5000.0
2.0.0.0
Method
System.String
A specifying the name to verify.
Verifies that the name is a valid qualified name as defined in the
W3C Extended Markup Language recommendation (REC-xml-names-19990114).
The , if it is a valid XML qualified name.
If contains a colon, is
thrown.
is or .
is not a valid XML qualified name.
0
1.0.5000.0
2.0.0.0
Method
System.String
To be added.
To be added.
To be added.
To be added.
2.0.0.0
Method
System.String
To be added.
To be added.
To be added.
To be added.
2.0.0.0
0