LookupNamespace() public method

public LookupNamespace ( String prefix ) : String
prefix String
return String
Ejemplo n.º 1
0
		public void DefaultXmlnsAttributeLookup ()
		{
			string xml = @"<!DOCTYPE X [
			<!ELEMENT X (Y)+>
			<!ENTITY baz 'urn:baz'>
			<!ATTLIST X
				xmlns CDATA 'urn:foo'
				xmlns:bar CDATA 'urn:bar'
				xmlns:baz CDATA #IMPLIED
				dummy CDATA 'dummy'
				baz:dummy CDATA 'dummy'>
			<!ELEMENT Y (#PCDATA)*>
			<!ATTLIST Y
				xmlns CDATA #IMPLIED
				xmlns:bar CDATA #IMPLIED>
			]>
			<X xmlns:baz='&baz;'><Y/><Y>text.</Y><Y xmlns='' xmlns:bar='urn:hoge'>text.</Y></X>";
			XmlValidatingReader xvr = new XmlValidatingReader (
				xml, XmlNodeType.Document, null);
			xvr.Read (); // DTD
			xvr.Read (); // whitespace
			xvr.Read ();
			Assert.AreEqual ("urn:foo", xvr.LookupNamespace (String.Empty), "#1-1");
			Assert.AreEqual ("urn:bar", xvr.LookupNamespace ("bar"), "#1-2");

			Assert.AreEqual ("urn:baz", xvr.LookupNamespace ("baz"), "#1-a");
			Assert.IsTrue (xvr.MoveToAttribute ("baz:dummy"), "#1-b");
			Assert.AreEqual ("urn:baz", xvr.NamespaceURI, "#1-c");

			Assert.IsTrue (xvr.MoveToAttribute ("dummy"), "#1-d");
			Assert.AreEqual (String.Empty, xvr.NamespaceURI, "#1-e");

			xvr.Read (); // first Y, empty element
			Assert.AreEqual ("urn:foo", xvr.LookupNamespace (String.Empty), "#2-1");
			Assert.AreEqual ("urn:bar", xvr.LookupNamespace ("bar"), "#2-2");
			xvr.Read (); // second Y, start element
			Assert.AreEqual ("urn:foo", xvr.LookupNamespace (String.Empty), "#3-1");
			Assert.AreEqual ("urn:bar", xvr.LookupNamespace ("bar"), "#3-2");
			xvr.Read (); // inside normal Y. Check inheritance
			Assert.AreEqual ("urn:foo", xvr.LookupNamespace (String.Empty), "#4-1");
			Assert.AreEqual ("urn:bar", xvr.LookupNamespace ("bar"), "#4-2");
			xvr.Read (); // second Y, end element
			Assert.AreEqual ("urn:foo", xvr.LookupNamespace (String.Empty), "#5-1");
			Assert.AreEqual ("urn:bar", xvr.LookupNamespace ("bar"), "#5-2");
			xvr.Read (); // third Y, suppresses default namespaces
			Assert.AreEqual (null, xvr.LookupNamespace (String.Empty), "#6-1");
			Assert.AreEqual ("urn:hoge", xvr.LookupNamespace ("bar"), "#6-2");
			xvr.Read (); // inside suppressing Y. Check inheritance
			Assert.AreEqual (null, xvr.LookupNamespace (String.Empty), "#7-1");
			Assert.AreEqual ("urn:hoge", xvr.LookupNamespace ("bar"), "#7-2");
			xvr.Read (); // end of suppressing element
			Assert.AreEqual (null, xvr.LookupNamespace (String.Empty), "#8-1");
			Assert.AreEqual ("urn:hoge", xvr.LookupNamespace ("bar"), "#8-2");
		}