本文整理匯總了C#中System.Xml.XmlValidatingReader.MoveToAttribute方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlValidatingReader.MoveToAttribute方法的具體用法?C# XmlValidatingReader.MoveToAttribute怎麽用?C# XmlValidatingReader.MoveToAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlValidatingReader
的用法示例。
在下文中一共展示了XmlValidatingReader.MoveToAttribute方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DefaultXmlnsAttributeLookup
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");
}
示例2: ResolveEntityReadAttributeValue
public void ResolveEntityReadAttributeValue ()
{
string dtd = "<!DOCTYPE root [<!ELEMENT root (#PCDATA)*><!ATTLIST root attr CDATA #REQUIRED><!ENTITY ent 'entity string'>]>";
string xml = dtd + "<root attr='&ent; text'>&ent;</root>";
dvr = new XmlValidatingReader (xml, XmlNodeType.Document, null);
dvr.Read (); // doctype
dvr.Read (); // root
dvr.MoveToAttribute (0); // attr
Assert.IsTrue (dvr.ReadAttributeValue ()); // Should read expanded text
Assert.AreEqual (XmlNodeType.Text, dvr.NodeType); // not EntityReference
Assert.AreEqual ("entity string text", dvr.Value);
Assert.IsTrue (!dvr.ReadAttributeValue ());
}