本文整理汇总了C#中System.Xml.XmlReader.ReadAttributeValue方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.ReadAttributeValue方法的具体用法?C# XmlReader.ReadAttributeValue怎么用?C# XmlReader.ReadAttributeValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlReader
的用法示例。
在下文中一共展示了XmlReader.ReadAttributeValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckPerspexRoot
public static bool CheckPerspexRoot(XmlReader reader)
{
try
{
while (!reader.IsStartElement())
{
reader.Read();
}
if (!reader.MoveToFirstAttribute())
return false;
do
{
if (reader.Name == "xmlns")
{
reader.ReadAttributeValue();
return reader.Value.ToLower() == PerspexNamespace;
}
} while (reader.MoveToNextAttribute());
return false;
}
catch
{
return false;
}
}
示例2: while
void IXmlSerializable.ReadXml(XmlReader reader)
{
reader.ReadStartElement();
while (reader.GetAttribute("key") != null)
{
reader.ReadAttributeValue();
this.Add(reader.GetAttribute("key"), reader.GetAttribute("value"));
reader.ReadStartElement("property");
}
reader.ReadEndElement();
}
示例3: Run
public static void Run(XmlReader reader, bool includeAttributes, bool includeAttributeValues = true)
{
using (StreamWriter output = File.CreateText(Path.Combine(Program.TempPath, reader.GetType().Name + "-output.csv"))) {
var properties = typeof(XmlReader).GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.GetIndexParameters().Length == 0 && !ignoredProperties.Contains(p.Name))
.ToArray();
output.WriteLine(CSV(properties.Select(p => p.Name)));
do {
output.WriteLine(CSV(properties.Select(p => ToString(p.GetValue(reader, null)))));
if (includeAttributes && reader.HasAttributes) {
for (int i = 0; i < reader.AttributeCount; i++) {
reader.MoveToAttribute(i);
output.WriteLine(CSV(properties.Select(p => ToString(p.GetValue(reader, null)))));
if (includeAttributeValues) {
reader.ReadAttributeValue();
output.WriteLine(CSV(properties.Select(p => ToString(p.GetValue(reader, null)))));
}
}
}
} while (reader.Read());
output.WriteLine(CSV(properties.Select(p => ToString(p.GetValue(reader, null)))));
}
}
示例4: VerifyAttributeValue
private void VerifyAttributeValue(XmlReader expectedReader, XmlReader actualReader, bool useReadAttributeValue)
{
this.VerifyReaderNodesAreEqual(expectedReader, actualReader);
if (expectedReader.NodeType != XmlNodeType.Attribute || !useReadAttributeValue)
{
return;
}
while (expectedReader.ReadAttributeValue())
{
this.Assert.AreEqual(true, actualReader.ReadAttributeValue(), "ReadAttributeValue differs.");
this.VerifyReaderNodesAreEqual(expectedReader, actualReader);
}
this.Assert.AreEqual(false, actualReader.ReadAttributeValue(), "ReadAttributeValue differs.");
this.VerifyReaderNodesAreEqual(expectedReader, actualReader);
}
示例5: WriteAttributes
/// <summary>
/// This method is overriden to filter out attributes which are not allowed
/// </summary>
public override void WriteAttributes(XmlReader reader, bool defattr)
{
if( this.FilterOutput )
{
// The following code is copied from implementation of XmlWriter's
// WriteAttributes method.
if (reader == null)
{
throw new ArgumentNullException("reader");
}
if ((reader.NodeType == XmlNodeType.Element) || (reader.NodeType == XmlNodeType.XmlDeclaration))
{
if (reader.MoveToFirstAttribute())
{
this.WriteAttributes(reader, defattr);
reader.MoveToElement();
}
}
else
{
if (reader.NodeType != XmlNodeType.Attribute)
{
throw new XmlException("Xml_InvalidPosition");
}
do
{
if (defattr || !reader.IsDefault)
{
// Check if the attribute is allowed
bool canWrite = false;
string attributeLocalName = reader.LocalName.ToLower();
foreach( string name in this.AllowedAttributes )
{
if( name == attributeLocalName )
{
canWrite = true;
break;
}
}
// If allowed, write the attribute
if( canWrite )
this.WriteStartAttribute(reader.Prefix, attributeLocalName,
reader.NamespaceURI);
while (reader.ReadAttributeValue())
{
if (reader.NodeType == XmlNodeType.EntityReference)
{
if( canWrite ) this.WriteEntityRef(reader.Name);
continue;
}
if( canWrite )this.WriteString(reader.Value);
}
if( canWrite ) this.WriteEndAttribute();
}
} while (reader.MoveToNextAttribute());
}
}
else
{
base.WriteAttributes( reader, defattr );
}
}
示例6: WriteAttributes
public override void WriteAttributes(XmlReader reader, bool defattr)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
if ((reader.NodeType == XmlNodeType.Element) || (reader.NodeType == XmlNodeType.XmlDeclaration))
{
if (reader.MoveToFirstAttribute())
{
this.WriteAttributes(reader, defattr);
reader.MoveToElement();
}
}
else
{
if (reader.NodeType != XmlNodeType.Attribute)
{
throw new XmlException("Xml_InvalidPosition");
}
do
{
if (defattr || !reader.IsDefault)
{
string attributename = reader.LocalName.ToLower();
this.WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
while (reader.ReadAttributeValue())
{
if (reader.NodeType == XmlNodeType.EntityReference)
{
this.WriteEntityRef(reader.Name);
continue;
}
string value = reader.Value;
if (BaseHref != null
&& LastStartElement == "a"
&& attributename == "href")
{
value = HtmlUriExtractor.TryCreate(
BaseHref, reader.Value, value);
}
if (BaseHref != null
&& (LastStartElement == "img" || LastStartElement == "embed")
&& attributename == "src")
{
value = HtmlUriExtractor.TryCreate(
BaseHref, reader.Value, value);
}
this.WriteString(value);
}
this.WriteEndAttribute();
}
} while (reader.MoveToNextAttribute());
}
}
示例7: ReadEndpointCheck
static void ReadEndpointCheck(XmlReader reader)
{
reader.MoveToAttribute ("name");
if (!reader.ReadAttributeValue ())
throw new ArgumentException ("Cannot read endpoint");
}
示例8: AppendAttributeValue
internal int AppendAttributeValue(XmlReader reader)
{
int charactersWritten = 0;
char quote = '"';//reader.QuoteChar;
//
// In !DOCTYPE, quote is '\0' for second public attribute.
// Protect ourselves from writing invalid XML by always
// supplying a valid quote char.
//
if (quote != '"' && quote != '\'') {
quote = '"';
}
charactersWritten += Write(quote);
while (reader.ReadAttributeValue()) {
if (reader.NodeType == XmlNodeType.Text) {
charactersWritten += AppendEscapeXmlString(reader.Value, true, quote);
}
else {
charactersWritten += AppendEntityRef(reader.Name);
}
}
charactersWritten += Write(quote);
return charactersWritten;
}
示例9: ConsumeReader
protected void ConsumeReader(XmlReader reader)
{
while (reader.Read())
{
string x = reader.Name + reader.NodeType + reader.Value;
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.HasAttributes)
{
reader.MoveToFirstAttribute();
int index = 0;
reader.MoveToAttribute(index);
index++;
while (reader.MoveToNextAttribute())
{
string name = reader.Name;
string value;
value = reader.GetAttribute(index);
value = reader.GetAttribute(name);
value = reader.GetAttribute(name, null);
reader.ReadAttributeValue();
reader.MoveToAttribute(index);
reader.MoveToAttribute(name, null);
index++;
}
}
}
if (reader.NodeType == XmlNodeType.EndElement)
{
reader.Skip();
}
}
}
示例10: WriteAttribute
private void WriteAttribute (XmlReader reader, bool defattr)
{
if (!defattr && reader.IsDefault)
return;
WriteStartAttribute (reader.Prefix, reader.LocalName, reader.NamespaceURI);
#if MOONLIGHT
// no ReadAttributeValue() in 2.1 profile.
WriteString (reader.Value);
#else
while (reader.ReadAttributeValue ()) {
switch (reader.NodeType) {
case XmlNodeType.Text:
WriteString (reader.Value);
break;
case XmlNodeType.EntityReference:
WriteEntityRef (reader.Name);
break;
}
}
#endif
WriteEndAttribute ();
}
示例11: WriteAttributes
// XmlReader Helper Methods
// Writes out all the attributes found at the current position in the specified XmlReader.
public virtual void WriteAttributes(XmlReader reader, bool defattr)
{
if (null == reader)
{
throw new ArgumentNullException(nameof(reader));
}
if (reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.XmlDeclaration)
{
if (reader.MoveToFirstAttribute())
{
WriteAttributes(reader, defattr);
reader.MoveToElement();
}
}
else if (reader.NodeType != XmlNodeType.Attribute)
{
throw new XmlException(SR.Xml_InvalidPosition, string.Empty);
}
else
{
do
{
// we need to check both XmlReader.IsDefault and XmlReader.SchemaInfo.IsDefault.
// If either of these is true and defattr=false, we should not write the attribute out
if (defattr || !reader.IsDefaultInternal)
{
WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
while (reader.ReadAttributeValue())
{
if (reader.NodeType == XmlNodeType.EntityReference)
{
WriteEntityRef(reader.Name);
}
else
{
WriteString(reader.Value);
}
}
WriteEndAttribute();
}
}
while (reader.MoveToNextAttribute());
}
}
示例12: ReadAttributeNodeValue
// Reads attribute from XmlReader and then creates attribute value children. XmlAttribute also uses this.
internal void ReadAttributeNodeValue (XmlReader reader, XmlAttribute attribute)
{
while (reader.ReadAttributeValue ()) {
if (reader.NodeType == XmlNodeType.EntityReference)
attribute.AppendChild (CreateEntityReference (reader.Name), false); // omit node type check
else
// Children of Attribute is restricted to CharacterData and EntityReference (Comment is not allowed).
attribute.AppendChild (CreateTextNode (reader.Value), false); // omit node type check
}
}
示例13: WriteAttributes
/// <summary>
/// This method is overriden to filter out attributes which are not allowed
/// </summary>
public override void WriteAttributes(XmlReader reader, bool defattr)
{
// The following code is copied from implementation of XmlWriter's
// WriteAttributes method.
if (reader == null)
{
throw new ArgumentNullException("reader");
}
if ((reader.NodeType == XmlNodeType.Element) || (reader.NodeType == XmlNodeType.XmlDeclaration))
{
if (reader.MoveToFirstAttribute())
{
try
{
this.WriteAttributes(reader, defattr);
}
catch { }
reader.MoveToElement();
}
}
else
{
if (reader.NodeType != XmlNodeType.Attribute)
{
throw new XmlException("Xml_InvalidPosition");
}
do
{
try
{
if (defattr || !reader.IsDefault)
{
// Check if the attribute is allowed
string attributeLocalName = reader.LocalName.ToLower();
AttributeTypes type = GetAttributeType(attributeLocalName);
if (!type.Equals(AttributeTypes.Remove))
{
//parse the attribute
string attribteValue = "";
while (reader.ReadAttributeValue())
{
if (reader.NodeType.Equals(XmlNodeType.Text))
attribteValue += reader.Value;
}
string parsedAttribteValue = ParseAttribute(attribteValue, type);
//write the
if (parsedAttribteValue.Length > 0)
{
this.WriteStartAttribute(attributeLocalName);
this.WriteRaw(parsedAttribteValue);
//this.WriteString(parsedAttribteValue);
this.WriteEndAttribute();
}
}
}
}
catch { }
}
while (reader.MoveToNextAttribute());
}
}
示例14: MoveToXmlDeclAttributes
public void MoveToXmlDeclAttributes (XmlReader xmlReader)
{
xmlReader.Read ();
this.AssertNodeValues ("#1", xmlReader,
XmlNodeType.XmlDeclaration,
0,
false,
"xml",
String.Empty,
"xml",
String.Empty,
"version=\"1.0\" standalone=\"yes\"",
2);
Assert.IsTrue (xmlReader.MoveToFirstAttribute (), "MoveToFirstAttribute");
this.AssertNodeValues ("#2", xmlReader,
XmlNodeType.Attribute,
0, // FIXME: might be 1
false,
"version",
String.Empty,
"version",
String.Empty,
"1.0",
2);
xmlReader.ReadAttributeValue ();
this.AssertNodeValues ("#3", xmlReader,
XmlNodeType.Text,
1, // FIXME might be 2
false,
String.Empty,
null, // FIXME: should be String.Empty,
String.Empty,
null, // FIXME: should be String.Empty,
"1.0",
2);
xmlReader.MoveToNextAttribute ();
this.AssertNodeValues ("#4", xmlReader,
XmlNodeType.Attribute,
0, // FIXME: might be 1
false,
"standalone",
String.Empty,
"standalone",
String.Empty,
"yes",
2);
xmlReader.ReadAttributeValue ();
this.AssertNodeValues ("#5", xmlReader,
XmlNodeType.Text,
1, // FIXME: might be 2
false,
String.Empty,
null, // FIXME: should be String.Empty,
String.Empty,
null, // FIXME: should be String.Empty,
"yes",
2);
}
示例15: WriteAttributes
public virtual void WriteAttributes(XmlReader reader, bool defattr)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
if ((reader.NodeType == XmlNodeType.Element) || (reader.NodeType == XmlNodeType.XmlDeclaration))
{
if (reader.MoveToFirstAttribute())
{
this.WriteAttributes(reader, defattr);
reader.MoveToElement();
}
}
else
{
if (reader.NodeType != XmlNodeType.Attribute)
{
throw new XmlException("Xml_InvalidPosition", string.Empty);
}
do
{
if (defattr || !reader.IsDefaultInternal)
{
this.WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
while (reader.ReadAttributeValue())
{
if (reader.NodeType == XmlNodeType.EntityReference)
{
this.WriteEntityRef(reader.Name);
}
else
{
this.WriteString(reader.Value);
}
}
this.WriteEndAttribute();
}
}
while (reader.MoveToNextAttribute());
}
}