XNamespaceResolver class methods

AddNamespace Method

This method finds a control by its name and returns a reference to that control on a form as a FrameworkElement type.

Syntax

public void AddNamespace(string prefix, string namespaceName)

Parameters

prefix

Type: System.String

The prefix of a namespace.

namespaceName

Type: System.String

The name of a namespace. To register a default namespace, use an empty string as prefix.

Example

XDocument xResponse = XDocument.Parse(@"
	<Message xmlns=""http://gateway.gov/schema/common/v1"">
		<Body>
			<GetCitizenAddressesResponse xmlns=""http://gateway.gov/schema/moi/ls/v1"">
				<Message xmlns=""http://gateway.gov/schema/common/v1"" />
				<Addresses>
					<Count>2</Count>
					<Items Source=""Gilys"">
						<Address>123th street 3A, apartment AB
Larnaca, Cyprus
						</Address>
				  	</Items>
					<Items Source=""ReNcor"">
						<Address>RenCOR Mock Address</Address>
            	</Items>
          	</Addresses>
			</GetCitizenAddressesResponse>
		</Body>
	</Message>");

XNamespaceResolver xresolver = new XNamespaceResolver();
xresolver.AddNamespace("com", "http://gateway.gov/schema/common/v1");
xresolver.AddNamespace("ls", "http://gateway.gov/schema/moi/ls/v1");

foreach (var xaddr in xResponse.XPathSelectElements("//ls:Addresses/ls:Items", xresolver))
{
	Console.WriteLine("Source: " + xaddrs.Attribute("Source").Value);

	XElement xAddress = xaddrs.XPathSelectElement("ls:Address", xresolver);
	if (xAddress != null)
		Console.WriteLine("Address: " + xaddrs.Value;
}