summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OpenId/Xrds/XrdsNode.cs
blob: 91c59bae6abc73caa8dda56fe52267dedabd10f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//-----------------------------------------------------------------------
// <copyright file="XrdsNode.cs" company="Outercurve Foundation, Scott Hanselman">
//     Copyright (c) Outercurve Foundation, Scott Hanselman. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.Xrds {
	using System;
	using System.Xml;
	using System.Xml.XPath;
	using DotNetOpenAuth.Messaging;
	using Validation;

	/// <summary>
	/// A node in an XRDS document.
	/// </summary>
	internal class XrdsNode {
		/// <summary>
		/// The XRD namespace xri://$xrd*($v*2.0)
		/// </summary>
		internal const string XrdNamespace = "xri://$xrd*($v*2.0)";

		/// <summary>
		/// The XRDS namespace xri://$xrds
		/// </summary>
		internal const string XrdsNamespace = "xri://$xrds";

		/// <summary>
		/// Initializes a new instance of the <see cref="XrdsNode"/> class.
		/// </summary>
		/// <param name="node">The node represented by this instance.</param>
		/// <param name="parentNode">The parent node.</param>
		protected XrdsNode(XPathNavigator node, XrdsNode parentNode) {
			Requires.NotNull(node, "node");
			Requires.NotNull(parentNode, "parentNode");

			this.Node = node;
			this.ParentNode = parentNode;
			this.XmlNamespaceResolver = this.ParentNode.XmlNamespaceResolver;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="XrdsNode"/> class.
		/// </summary>
		/// <param name="document">The document's root node, which this instance represents.</param>
		protected XrdsNode(XPathNavigator document) {
			Requires.NotNull(document, "document");
			Requires.That(document.NameTable != null, "document", "requires document.NameTable != null");

			this.Node = document;
			this.XmlNamespaceResolver = new XmlNamespaceManager(document.NameTable);
		}

		/// <summary>
		/// Gets the node.
		/// </summary>
		internal XPathNavigator Node { get; private set; }

		/// <summary>
		/// Gets the parent node, or null if this is the root node.
		/// </summary>
		protected internal XrdsNode ParentNode { get; private set; }

		/// <summary>
		/// Gets the XML namespace resolver to use in XPath expressions.
		/// </summary>
		protected internal XmlNamespaceManager XmlNamespaceResolver { get; private set; }
	}
}