本文整理匯總了C#中System.Xml.XmlElement.GetAttributeNode方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlElement.GetAttributeNode方法的具體用法?C# XmlElement.GetAttributeNode怎麽用?C# XmlElement.GetAttributeNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlElement
的用法示例。
在下文中一共展示了XmlElement.GetAttributeNode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Load
public override void Load (XmlElement filenode, FilePath baseDirectory)
{
var extAtt = filenode.GetAttributeNode ("extension");
if (extAtt != null)
extension = extAtt.Value ?? "";
propertyInnerText = filenode.InnerText;
if (propertyInnerText == null)
throw new InvalidOperationException ("Property is missing its inner text");
typeAtt = filenode.GetAttributeNode ("type");
if (typeAtt == null)
throw new InvalidOperationException ("Property is missing the type attribute");
if (String.IsNullOrEmpty (typeAtt.Value))
throw new InvalidOperationException ("Property's type attribute is empty");
if (String.IsNullOrEmpty (filenode.InnerText))
throw new InvalidOperationException ("Property is empty");
}
示例2: assert_throttle
public static IAssertion assert_throttle(XmlElement config)
{
var delay = new TimeSpan();
XmlAttribute attribute = config.GetAttributeNode("delayTimeSpan");
if (attribute != null)
{
delay = TimeSpan.Parse(attribute.Value);
}
bool trace = false;
attribute = config.GetAttributeNode("traceThrottledExceptions");
if (attribute != null)
{
trace = bool.Parse(attribute.Value);
}
return new ThrottleAssertion(delay, trace);
}
示例3: LoadData
/// <summary>
/// Extracts the data from the DOM tree below the indicated context
/// <see cref="XmlElement"/> and create a suitable <see crel="Release"/>
/// structure to add to the indicated <see cref="Specification"/>.
/// </summary>
/// <param name="specification">The owning <see cref="Specification"/>.</param>
/// <param name="context">The context <see cref="XmlElement"/> containing data</param>
/// <param name="loadedSchemas">A dictionary of all ready loaded schemas.</param>
public virtual void LoadData(Specification specification, XmlElement context,
Dictionary<string, SchemaRelease> loadedSchemas)
{
XmlAttribute id = context.GetAttributeNode ("id");
SchemaRelease release = new SchemaRelease (specification,
GetVersion (context), GetNamespaceUri (context),
GetSchemaLocation (context), GetPreferredPrefix (context),
GetAlternatePrefix (context), GetRootElements (context));
HandleImports (release, context, loadedSchemas);
if (id != null) loadedSchemas.Add (id.Value, release);
}
示例4: SortAttributesAttributes
private void SortAttributesAttributes(XmlElement el)
{
ArrayList al = new ArrayList();
foreach (XmlAttribute a in el.Attributes)
al.Add(a.Name);
al.Sort();
string[] names = (string[])al.ToArray(typeof(string));
al.Clear();
foreach (string name in names)
al.Add(el.RemoveAttributeNode(
el.GetAttributeNode(name)));
foreach (XmlAttribute a in al)
// Exclude xmlns="" here.
if (a.Name != "xmlns")// || a.Value != String.Empty)
el.SetAttributeNode(a);
}
示例5: LoadData
/// <summary>
/// Extracts the data from the DOM tree below the indicated context
/// <see cref="XmlElement"/> and create a suitable <see cref="HandCoded.Meta.Release"/>
/// structure to add to the indicated <see cref="HandCoded.Meta.Specification"/>.
/// </summary>
/// <param name="specification">The owning <see cref="HandCoded.Meta.Specification"/>.</param>
/// <param name="context">The context <see cref="XmlElement"/> containing data</param>
/// <param name="loadedSchemas">A dictionary of all ready loaded schemas.</param>
public override void LoadData(HandCoded.Meta.Specification specification, XmlElement context,
Dictionary<string, HandCoded.Meta.SchemaRelease> loadedSchemas)
{
XmlAttribute id = context.GetAttributeNode ("id");
SchemaRelease release = new SchemaRelease (specification,
GetVersion (context), GetNamespaceUri (context),
GetSchemaLocation (context), GetPreferredPrefix (context),
GetAlternatePrefix (context),
new FpMLInstanceInitialiser (),
new FpMLSchemaRecogniser (), GetRootElements (context),
GetSchemeDefaults (context), GetSchemeCollection (context));
HandleImports (release, context, loadedSchemas);
if (id != null) loadedSchemas.Add (id.Value, release);
}
示例6: InspectProgressTextElement
/// <summary>
/// Inspects a ProgressText element.
/// </summary>
/// <param name="element">The ProgressText element to inspect.</param>
private void InspectProgressTextElement(XmlElement element)
{
XmlAttribute template = element.GetAttributeNode("Template");
if (null != template && String.Empty == template.Value)
{
this.OnError(InspectorTestType.ProgressTextTemplateEmpty, element, "The ProgressText/@Template attribute's value cannot be the empty string.");
element.Attributes.Remove(template);
}
}
示例7: InspectMediaElement
/// <summary>
/// Inspects a Media element.
/// </summary>
/// <param name="element">The Media element to inspect.</param>
private void InspectMediaElement(XmlElement element)
{
XmlAttribute src = element.GetAttributeNode("src");
if (null != src)
{
this.OnError(InspectorTestType.SrcIsDeprecated, src, "The Media/@src attribute has been deprecated. Use the Layout attribute instead.");
XmlAttribute layout = element.OwnerDocument.CreateAttribute("Layout");
layout.Value = src.Value;
element.Attributes.InsertAfter(layout, src);
element.Attributes.Remove(src);
}
}
示例8: InspectFileSearchElement
/// <summary>
/// Inspects a FileSearch element.
/// </summary>
/// <param name="element">The FileSearch element to inspect.</param>
private void InspectFileSearchElement(XmlElement element)
{
XmlAttribute name = element.GetAttributeNode("Name");
XmlAttribute longName = element.GetAttributeNode("LongName");
// check for a short/long filename separator in the Name attribute
if (null != name && 0 <= name.Value.IndexOf('|'))
{
if (null == longName) // long name is not present, split the Name if possible
{
string[] names = name.Value.Split("|".ToCharArray());
// this appears to be splittable
if (2 == names.Length)
{
this.OnError(InspectorTestType.FileSearchNamesCombined, element, "The FileSearch/@Name attribute appears to contain both a short and long file name. It may only contain an 8.3 file name. Also use the LongName attribute to specify a longer name.");
// fix the short name
name.Value = names[0];
// insert the new LongName attribute after the previous Name attribute
longName = element.OwnerDocument.CreateAttribute("LongName");
longName.Value = names[1];
element.Attributes.InsertAfter(longName, name);
}
}
}
}
示例9: InspectControlElement
/// <summary>
/// Inspects a Control element.
/// </summary>
/// <param name="element">The Control element to inspect.</param>
private void InspectControlElement(XmlElement element)
{
XmlAttribute checkBoxValue = element.GetAttributeNode("CheckBoxValue");
if (null != checkBoxValue && String.Empty == checkBoxValue.Value)
{
this.OnError(InspectorTestType.IniFileValueEmpty, element, "The Control/@CheckBoxValue attribute's value cannot be the empty string.");
element.Attributes.Remove(checkBoxValue);
}
}
示例10: InspectClassElement
/// <summary>
/// Inspects a Class element.
/// </summary>
/// <param name="element">The Class element to inspect.</param>
private void InspectClassElement(XmlElement element)
{
bool advertised = false;
XmlAttribute description = element.GetAttributeNode("Description");
XmlAttribute relativePath = element.GetAttributeNode("RelativePath");
if (null != description && String.Empty == description.Value)
{
this.OnError(InspectorTestType.ClassDescriptionEmpty, element, "The Class/@Description attribute's value cannot be an empty string.");
element.Attributes.Remove(description);
}
if (null != relativePath)
{
// check if this element or any of its parents is advertised
for (XmlNode node = element; null != node; node = node.ParentNode)
{
if (node.Attributes != null)
{
XmlNode advertise = node.Attributes.GetNamedItem("Advertise");
if (null != advertise && "yes" == advertise.Value)
{
advertised = true;
}
}
}
if (advertised) // if advertised, then RelativePath="no" is unnecessary since its the default value
{
if ("no" == relativePath.Value)
{
this.OnVerbose(element, "The Class/@RelativePath attribute with value 'no' is not necessary since this element is advertised.");
element.Attributes.Remove(relativePath);
}
}
else // if there is no advertising, then the RelativePath attribute is not allowed
{
this.OnError(InspectorTestType.ClassRelativePathMustBeAdvertised, element, "The Class/@RelativePath attribute is not supported for non-advertised Class elements.");
element.Attributes.Remove(relativePath);
}
}
}
示例11: InspectWebApplicationExtensionElement
/// <summary>
/// Inspects a WebApplicationExtension element.
/// </summary>
/// <param name="element">The WebApplicationExtension element to inspect.</param>
private void InspectWebApplicationExtensionElement(XmlElement element)
{
XmlAttribute extension = element.GetAttributeNode("Extension");
XmlAttribute id = element.GetAttributeNode("Id");
if (null != id)
{
// an empty Id attribute value should be replaced with "*"
if (String.Empty == id.Value)
{
this.OnError(InspectorTestType.WebApplicationExtensionIdEmpty, element, "The WebApplicationExtension/@Id attribute's value cannot be an empty string. Use '*' for the value instead.");
id.Value = "*";
}
// Id has been deprecated, use Extension instead
if (null == extension)
{
this.OnError(InspectorTestType.WebApplicationExtensionIdDeprecated, element, "The WebApplicationExtension/@Id attribute has been deprecated. Use the Extension attribute instead.");
extension = element.OwnerDocument.CreateAttribute("Extension");
extension.Value = id.Value;
element.Attributes.InsertAfter(extension, id);
element.Attributes.Remove(id);
}
}
}
示例12: ParseArgument
private static object ParseArgument(ParameterInfo parameter, XmlElement config)
{
Debug.Assert(parameter != null);
Debug.Assert(config != null);
var name = parameter.Name;
var type = parameter.ParameterType;
string text;
var attribute = config.GetAttributeNode(name);
if (attribute != null)
{
text = attribute.Value;
}
else
{
var element = config[name];
if (element == null)
return null;
text = element.InnerText;
}
if (type == typeof(IContextExpression))
return new WebDataBindingExpression(text);
if (type == typeof(Type))
return TypeResolution.GetType(text);
if (type == typeof(bool))
{
text = text.Trim().ToLowerInvariant();
return Boolean.TrueString.Equals(StringTranslation.Translate(Boolean.TrueString, text, _truths));
}
var converter = TypeDescriptor.GetConverter(type);
return converter.ConvertFromInvariantString(text);
}
示例13: MoveToAttributeFromElement
private bool MoveToAttributeFromElement(XmlElement elem, string name, string ns)
{
XmlAttribute node = null;
if (ns.Length == 0)
{
node = elem.GetAttributeNode(name);
}
else
{
node = elem.GetAttributeNode(name, ns);
}
if (node != null)
{
this.bOnAttrVal = false;
this.elemNode = elem;
this.curNode = node;
this.attrIndex = elem.Attributes.FindNodeOffsetNS(node);
if (this.attrIndex != -1)
{
return true;
}
}
return false;
}
示例14: GetAttributeFromElement
private string GetAttributeFromElement(XmlElement elem, string name, string ns)
{
XmlAttribute attributeNode = elem.GetAttributeNode(name, ns);
if (attributeNode != null)
{
return attributeNode.Value;
}
return null;
}
示例15: PathHasDuplicateNamespace
private bool PathHasDuplicateNamespace(XmlElement top, XmlElement bottom, string localName)
{
string strReservedXmlns = this.document.strReservedXmlns;
while ((bottom != null) && (bottom != top))
{
if (bottom.GetAttributeNode(localName, strReservedXmlns) != null)
{
return true;
}
bottom = bottom.ParentNode as XmlElement;
}
return false;
}