本文整理匯總了C#中System.Xml.XmlValidatingReader.MoveToNextAttribute方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlValidatingReader.MoveToNextAttribute方法的具體用法?C# XmlValidatingReader.MoveToNextAttribute怎麽用?C# XmlValidatingReader.MoveToNextAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlValidatingReader
的用法示例。
在下文中一共展示了XmlValidatingReader.MoveToNextAttribute方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: TestPreserveEntityNotOnDotNet
// it used to be regarded as MS bug but it was not really.
public void TestPreserveEntityNotOnDotNet ()
{
string intSubset = "<!ELEMENT root EMPTY><!ATTLIST root foo CDATA 'foo-def' bar CDATA 'bar-def'><!ENTITY ent 'entity string'>";
string dtd = "<!DOCTYPE root [" + intSubset + "]>";
string xml = dtd + "<root foo='&ent;' bar='internal &ent; value' />";
dvr = PrepareXmlReader (xml);
dvr.EntityHandling = EntityHandling.ExpandCharEntities;
dvr.Read (); // DTD
dvr.Read ();
Assert.AreEqual (XmlNodeType.Element, dvr.NodeType);
Assert.AreEqual ("root", dvr.Name);
Assert.IsTrue (dvr.MoveToFirstAttribute ());
Assert.AreEqual ("foo", dvr.Name);
Assert.AreEqual ("entity string", dvr.Value);
// ReadAttributeValue()
Assert.IsTrue (dvr.ReadAttributeValue ());
Assert.AreEqual (XmlNodeType.EntityReference, dvr.NodeType);
Assert.AreEqual ("ent", dvr.Name);
Assert.AreEqual (String.Empty, dvr.Value);
Assert.IsTrue (!dvr.ReadAttributeValue ());
// bar
Assert.IsTrue (dvr.MoveToNextAttribute ());
Assert.AreEqual ("bar", dvr.Name);
Assert.AreEqual ("internal entity string value", dvr.Value);
// ReadAttributeValue()
Assert.IsTrue (dvr.ReadAttributeValue ());
Assert.AreEqual (XmlNodeType.Text, dvr.NodeType);
Assert.AreEqual (String.Empty, dvr.Name);
Assert.AreEqual ("internal ", dvr.Value);
Assert.IsTrue (dvr.ReadAttributeValue ());
Assert.AreEqual (XmlNodeType.EntityReference, dvr.NodeType);
Assert.AreEqual ("ent", dvr.Name);
Assert.AreEqual (String.Empty, dvr.Value);
Assert.IsTrue (dvr.ReadAttributeValue ());
Assert.AreEqual (XmlNodeType.Text, dvr.NodeType);
Assert.AreEqual (String.Empty, dvr.Name);
Assert.AreEqual (" value", dvr.Value);
// ValidationType = None
dvr = PrepareXmlReader (xml);
dvr.EntityHandling = EntityHandling.ExpandCharEntities;
dvr.ValidationType = ValidationType.None;
dvr.Read (); // DTD
dvr.Read ();
Assert.AreEqual (XmlNodeType.Element, dvr.NodeType);
Assert.AreEqual ("root", dvr.Name);
// foo
Assert.IsTrue (dvr.MoveToFirstAttribute ());
Assert.AreEqual ("foo", dvr.Name);
Assert.AreEqual ("entity string", dvr.Value);
// ReadAttributeValue()
Assert.IsTrue (dvr.ReadAttributeValue ());
Assert.AreEqual (XmlNodeType.EntityReference, dvr.NodeType);
Assert.AreEqual ("ent", dvr.Name);
Assert.AreEqual (String.Empty, dvr.Value);
Assert.IsTrue (!dvr.ReadAttributeValue ());
// bar
Assert.IsTrue (dvr.MoveToNextAttribute ());
Assert.AreEqual ("bar", dvr.Name);
Assert.AreEqual ("internal entity string value", dvr.Value);
// ReadAttributeValue()
Assert.IsTrue (dvr.ReadAttributeValue ());
Assert.AreEqual (XmlNodeType.Text, dvr.NodeType);
Assert.AreEqual (String.Empty, dvr.Name);
Assert.AreEqual ("internal ", dvr.Value);
Assert.IsTrue (dvr.ReadAttributeValue ());
Assert.AreEqual (XmlNodeType.EntityReference, dvr.NodeType);
Assert.AreEqual ("ent", dvr.Name);
Assert.AreEqual (String.Empty, dvr.Value);
Assert.IsTrue (dvr.ReadAttributeValue ());
Assert.AreEqual (XmlNodeType.Text, dvr.NodeType);
Assert.AreEqual (String.Empty, dvr.Name);
Assert.AreEqual (" value", dvr.Value);
}
示例2: TestNormalization
public void TestNormalization ()
{
string intSubset = "<!ELEMENT root EMPTY>"
+ "<!ATTLIST root foo ID #REQUIRED"
+ " bar NMTOKEN #IMPLIED "
+ " baz NMTOKENS #IMPLIED "
+ " quux CDATA #IMPLIED >";
string dtd = "<!DOCTYPE root [" + intSubset + "]>";
string xml = dtd + "<root foo=' id1 ' bar=' nameToken ' baz=' list of\r\nname token' quux=' quuux\tquuux\t ' />";
dvr = PrepareXmlReader (xml);
((XmlTextReader) dvr.Reader).Normalization = true;
dvr.EntityHandling = EntityHandling.ExpandEntities;
dvr.Read (); // DTD
dvr.Read ();
Assert.AreEqual (XmlNodeType.Element, dvr.NodeType);
Assert.AreEqual ("root", dvr.Name);
Assert.IsTrue (dvr.MoveToFirstAttribute ());
Assert.AreEqual ("foo", dvr.Name);
Assert.AreEqual ("id1", dvr.Value);
Assert.IsTrue (dvr.MoveToNextAttribute ());
Assert.AreEqual ("bar", dvr.Name);
Assert.AreEqual ("nameToken", dvr.Value);
Assert.IsTrue (dvr.MoveToNextAttribute ());
Assert.AreEqual ("baz", dvr.Name);
Assert.AreEqual ("list of name token", dvr.Value);
Assert.IsTrue (dvr.MoveToNextAttribute ());
Assert.AreEqual ("quux", dvr.Name);
Assert.AreEqual (" quuux quuux ", dvr.Value);
}
示例3: TestExpandEntity
public void TestExpandEntity ()
{
string intSubset = "<!ELEMENT root (#PCDATA)><!ATTLIST root foo CDATA 'foo-def' bar CDATA 'bar-def'><!ENTITY ent 'entity string'>";
string dtd = "<!DOCTYPE root [" + intSubset + "]>";
string xml = dtd + "<root foo='&ent;' bar='internal &ent; value'>&ent;</root>";
dvr = PrepareXmlReader (xml);
dvr.EntityHandling = EntityHandling.ExpandEntities;
dvr.Read (); // DTD
dvr.Read ();
Assert.AreEqual (XmlNodeType.Element, dvr.NodeType);
Assert.AreEqual ("root", dvr.Name);
Assert.IsTrue (dvr.MoveToFirstAttribute ());
Assert.AreEqual ("foo", dvr.Name);
Assert.AreEqual ("entity string", dvr.Value);
Assert.IsTrue (dvr.MoveToNextAttribute ());
Assert.AreEqual ("bar", dvr.Name);
Assert.AreEqual ("internal entity string value", dvr.Value);
Assert.AreEqual ("entity string", dvr.ReadString ());
// ValidationType = None
dvr = PrepareXmlReader (xml);
dvr.EntityHandling = EntityHandling.ExpandEntities;
dvr.ValidationType = ValidationType.None;
dvr.Read (); // DTD
dvr.Read ();
Assert.AreEqual (XmlNodeType.Element, dvr.NodeType);
Assert.AreEqual ("root", dvr.Name);
Assert.IsTrue (dvr.MoveToFirstAttribute ());
Assert.AreEqual ("foo", dvr.Name);
Assert.AreEqual ("entity string", dvr.Value);
Assert.IsTrue (dvr.MoveToNextAttribute ());
Assert.AreEqual ("bar", dvr.Name);
Assert.AreEqual ("internal entity string value", dvr.Value);
Assert.AreEqual ("entity string", dvr.ReadString ());
}
示例4: BuildAttrs
// 根據xml編輯框中的內容創建屬性
void BuildAttrs()
{
//this.SetFreshValue();
Debug.Assert(m_attrsExpand == ExpandStyle.Collapse, "不是閉合狀態不要用本函數");
NameTable nt = new NameTable();
// 創建名字空間
XmlNamespaceManager nsmgr = GatherOuterNamespaces(
this,
nt);
XmlParserContext context = new XmlParserContext(nt,
nsmgr,
null,
XmlSpace.None);
string strAttrsXml = "";
// 2.得到attributes關閉時的text
XmlText oText = this.GetAttributesText();
if (oText != null)
{
strAttrsXml = oText.Text.Trim();
if (strAttrsXml != "")
strAttrsXml = " " + strAttrsXml;
}
else
{
Debug.Assert(false, "必須有text對象");
}
string strFragmentXml = "<" + this.Name + strAttrsXml + "/>";
/*
TextReader tr = new StringReader(strFragmentXml);
XmlReaderSettings settings = new XmlReaderSettings();
settings..XmlResolver = resolver;
XmlReader reader = XmlReader.Create(tr, settings,
context);
* */
// 過一段時間做XmlSchema校驗
XmlValidatingReader reader =
new XmlValidatingReader(strFragmentXml,
XmlNodeType.Element,
context);
// 不根據schema進行校驗
reader.ValidationType = ValidationType.None;
this.attrs = new ItemList();
while(true)
{
if (reader.Read() == false)
break;
if (reader.MoveToFirstAttribute() == false)
goto CONTINUE;
while(true)
{
AttrItem attr = this.m_document.CreateAttrItem(reader.Name);
attr.Initial(reader);
this.AppendAttrInternal(attr,false,true);
if (reader.MoveToNextAttribute() == false)
break;
}
CONTINUE:
break;
}
}
示例5: TestReadTypedAttributeValue
public void TestReadTypedAttributeValue ()
{
string xml = "<root attr='12'></root>";
XmlSchema schema = new XmlSchema ();
XmlSchemaElement elem = new XmlSchemaElement ();
elem.Name = "root";
XmlSchemaComplexType ct = new XmlSchemaComplexType ();
XmlSchemaAttribute attr = new XmlSchemaAttribute ();
attr.Name = "attr";
attr.SchemaTypeName = new XmlQualifiedName ("int", XmlSchema.Namespace);
ct.Attributes.Add (attr);
elem.SchemaType = ct;
schema.Items.Add (elem);
xvr = PrepareXmlReader (xml);
xvr.Schemas.Add (schema);
xvr.Read ();
Assert.AreEqual ("root", xvr.Name);
Assert.IsTrue (xvr.MoveToNextAttribute ()); // attr
Assert.AreEqual ("attr", xvr.Name);
XmlSchemaDatatype dt = xvr.SchemaType as XmlSchemaDatatype;
Assert.IsNotNull (dt);
Assert.AreEqual (typeof (int), dt.ValueType);
Assert.AreEqual (XmlTokenizedType.None, dt.TokenizedType);
object o = xvr.ReadTypedValue ();
Assert.AreEqual (XmlNodeType.Attribute, xvr.NodeType);
Assert.AreEqual (typeof (int), o.GetType ());
int n = (int) o;
Assert.AreEqual (12, n);
Assert.IsTrue (xvr.ReadAttributeValue ()); // can read = seems not proceed.
}
示例6: PolicyDocumentReadWrite
/// <summary>
/// Creates a new PolicyDocument using the XmlReader instance provided with the possibility of writing.
/// </summary>
/// <param name="reader">The XmlReader positioned at the begining of the document.</param>
/// <param name="schemaVersion">The version of the schema that will be used to validate.</param>
public PolicyDocumentReadWrite(XmlReader reader, XacmlVersion schemaVersion)
{
// Validate the parameters
if (reader == null)
{
throw new ArgumentNullException("reader");
}
_schemaVersion = schemaVersion;
// Prepare Xsd validation
#if NET10
XmlValidatingReader vreader = new XmlValidatingReader( reader );
#endif
#if NET20
ValidationEventHandler validationHandler = vreader_ValidationEventHandler;
XmlReaderSettings settings = new XmlReaderSettings {ValidationType = ValidationType.Schema};
settings.ValidationEventHandler += validationHandler;
XmlReader vreader = null;
#endif
try
{
switch (schemaVersion)
{
case XacmlVersion.Version10:
case XacmlVersion.Version11:
{
Stream schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml10PolicySchemaResourceName);
#if NET10
XmlTextReader schemaReader = new XmlTextReader(schemaStream);
vreader.Schemas.Add( PolicySchema1.Namespaces.Policy, schemaReader );
#endif
#if NET20
if (_compiledSchemas11 == null)
{
_compiledSchemas11 = new XmlSchemaSet();
_compiledSchemas11.Add(XmlSchema.Read(schemaStream, validationHandler));
_compiledSchemas11.Compile();
}
settings.Schemas.Add(_compiledSchemas11);
#endif
break;
}
case XacmlVersion.Version20:
{
Stream schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml20PolicySchemaResourceName);
#if NET10
XmlTextReader schemaReader = new XmlTextReader(schemaStream);
vreader.Schemas.Add( PolicySchema2.Namespaces.Policy, schemaReader );
#endif
#if NET20
if (_compiledSchemas20 == null)
{
_compiledSchemas20 = new XmlSchemaSet();
_compiledSchemas20.Add(XmlSchema.Read(schemaStream, validationHandler));
_compiledSchemas20.Compile();
}
settings.Schemas.Add(_compiledSchemas20);
#endif
break;
}
default:
throw new ArgumentException(Resource.ResourceManager[Resource.MessageKey.exc_invalid_version_parameter_value], "version");
}
#if NET10
vreader.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler( vreader_ValidationEventHandler );
#endif
#if NET20
vreader = XmlReader.Create(reader, settings);
#endif
// Read and validate the document.
while (vreader.Read())
{
//Read all the namespaces and keep them in the _namespaces hashtable.
if (vreader.HasAttributes)
{
while (vreader.MoveToNextAttribute())
{
if (vreader.LocalName == PolicySchema1.Namespaces.XMLNS)
{
_namespaces.Add(vreader.Prefix, vreader.Value);
}
else if (vreader.Prefix == PolicySchema1.Namespaces.XMLNS)
{
_namespaces.Add(vreader.LocalName, vreader.Value);
}
}
vreader.MoveToElement();
}
// Check the first element of the document and proceeds to read the contents
// depending on the first node name.
switch (vreader.LocalName)
{
case PolicySchema1.PolicySetElement.PolicySet:
//.........這裏部分代碼省略.........
示例7: TestPreserveEntity
public void TestPreserveEntity ()
{
string intSubset = "<!ELEMENT root EMPTY><!ATTLIST root foo CDATA 'foo-def' bar CDATA 'bar-def'><!ENTITY ent 'entity string'>";
string dtd = "<!DOCTYPE root [" + intSubset + "]>";
string xml = dtd + "<root foo='&ent;' bar='internal &ent; value' />";
dvr = PrepareXmlReader (xml);
dvr.EntityHandling = EntityHandling.ExpandCharEntities;
dvr.Read (); // DTD
dvr.Read ();
AssertEquals (XmlNodeType.Element, dvr.NodeType);
AssertEquals ("root", dvr.Name);
Assert (dvr.MoveToFirstAttribute ());
AssertEquals ("foo", dvr.Name);
// MS BUG: it returns "entity string", however, entity should not be exanded.
// ReadAttributeValue()
Assert (dvr.ReadAttributeValue ());
AssertEquals (XmlNodeType.EntityReference, dvr.NodeType);
AssertEquals ("ent", dvr.Name);
AssertEquals ("", dvr.Value);
Assert (!dvr.ReadAttributeValue ());
// bar
Assert (dvr.MoveToNextAttribute ());
AssertEquals ("bar", dvr.Name);
// ReadAttributeValue()
Assert (dvr.ReadAttributeValue ());
AssertEquals (XmlNodeType.Text, dvr.NodeType);
AssertEquals ("", dvr.Name);
AssertEquals ("internal ", dvr.Value);
Assert (dvr.ReadAttributeValue ());
AssertEquals (XmlNodeType.EntityReference, dvr.NodeType);
AssertEquals ("ent", dvr.Name);
AssertEquals ("", dvr.Value);
Assert (dvr.ReadAttributeValue ());
AssertEquals (XmlNodeType.Text, dvr.NodeType);
AssertEquals ("", dvr.Name);
AssertEquals (" value", dvr.Value);
// ValidationType = None
dvr = PrepareXmlReader (xml);
dvr.EntityHandling = EntityHandling.ExpandCharEntities;
dvr.ValidationType = ValidationType.None;
dvr.Read (); // DTD
dvr.Read ();
AssertEquals (XmlNodeType.Element, dvr.NodeType);
AssertEquals ("root", dvr.Name);
// foo
Assert (dvr.MoveToFirstAttribute ());
AssertEquals ("foo", dvr.Name);
// ReadAttributeValue()
Assert (dvr.ReadAttributeValue ());
AssertEquals (XmlNodeType.EntityReference, dvr.NodeType);
AssertEquals ("ent", dvr.Name);
AssertEquals ("", dvr.Value);
Assert (!dvr.ReadAttributeValue ());
// bar
Assert (dvr.MoveToNextAttribute ());
AssertEquals ("bar", dvr.Name);
// ReadAttributeValue()
Assert (dvr.ReadAttributeValue ());
AssertEquals (XmlNodeType.Text, dvr.NodeType);
AssertEquals ("", dvr.Name);
AssertEquals ("internal ", dvr.Value);
Assert (dvr.ReadAttributeValue ());
AssertEquals (XmlNodeType.EntityReference, dvr.NodeType);
AssertEquals ("ent", dvr.Name);
AssertEquals ("", dvr.Value);
Assert (dvr.ReadAttributeValue ());
AssertEquals (XmlNodeType.Text, dvr.NodeType);
AssertEquals ("", dvr.Name);
AssertEquals (" value", dvr.Value);
}