本文整理汇总了C#中XmlElement.HasAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XmlElement.HasAttribute方法的具体用法?C# XmlElement.HasAttribute怎么用?C# XmlElement.HasAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlElement
的用法示例。
在下文中一共展示了XmlElement.HasAttribute方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: readStringFromAttribute
private string readStringFromAttribute(XmlElement element, String attribute)
{
if(element.HasAttribute(attribute)) {
return element.Attributes[attribute].Value;
}
return null;
}
示例2: DeserializeElement
public IUnitTestElement DeserializeElement(XmlElement parent, IUnitTestElement parentElement)
{
if (!parent.HasAttribute("type"))
throw new ArgumentException("Element has no Type attribute");
ReadFromXmlFunc func;
if (DeserialiseMap.TryGetValue(parent.GetAttribute("type"), out func))
return func(parent, parentElement, _solution, _unitTestElementFactory);
throw new ArgumentException("Element has no Type attribute");
}
示例3: readFromAttribute
private float? readFromAttribute(XmlElement element, String attribute)
{
if(element.HasAttribute(attribute)) {
string w = element.Attributes[attribute].Value;
try {
return Convert.ToSingle(w);
}
catch(Exception e) {
Debug.LogWarning("Bad format for menu " + attribute + " '" + w + "': " + e.Message);
}
}
return default(float?);
}
示例4: LoadTerritoryTagMetadata
public static PhoneMetadata.Builder LoadTerritoryTagMetadata(String regionCode, XmlElement element,
String nationalPrefix,
String nationalPrefixFormattingRule)
{
var metadata = new PhoneMetadata.Builder();
metadata.SetId(regionCode);
metadata.SetCountryCode(int.Parse(element.GetAttribute(COUNTRY_CODE)));
if (element.HasAttribute(LEADING_DIGITS))
metadata.SetLeadingDigits(ValidateRE(element.GetAttribute(LEADING_DIGITS)));
metadata.SetInternationalPrefix(ValidateRE(element.GetAttribute(INTERNATIONAL_PREFIX)));
if (element.HasAttribute(PREFERRED_INTERNATIONAL_PREFIX))
{
String preferredInternationalPrefix = element.GetAttribute(PREFERRED_INTERNATIONAL_PREFIX);
metadata.SetPreferredInternationalPrefix(preferredInternationalPrefix);
}
if (element.HasAttribute(NATIONAL_PREFIX_FOR_PARSING))
{
metadata.SetNationalPrefixForParsing(
ValidateRE(element.GetAttribute(NATIONAL_PREFIX_FOR_PARSING)));
if (element.HasAttribute(NATIONAL_PREFIX_TRANSFORM_RULE))
{
metadata.SetNationalPrefixTransformRule(
ValidateRE(element.GetAttribute(NATIONAL_PREFIX_TRANSFORM_RULE)));
}
}
if (!String.IsNullOrEmpty(nationalPrefix))
{
metadata.SetNationalPrefix(nationalPrefix);
if (!metadata.HasNationalPrefixForParsing)
metadata.SetNationalPrefixForParsing(nationalPrefix);
}
if (element.HasAttribute(PREFERRED_EXTN_PREFIX))
{
metadata.SetPreferredExtnPrefix(element.GetAttribute(PREFERRED_EXTN_PREFIX));
}
if (element.HasAttribute(MAIN_COUNTRY_FOR_CODE))
{
metadata.SetMainCountryForCode(true);
}
if (element.HasAttribute(LEADING_ZERO_POSSIBLE))
{
metadata.SetLeadingZeroPossible(true);
}
return metadata;
}
示例5: LoadCountryMetadata
public static PhoneMetadata LoadCountryMetadata(String regionCode, XmlElement element)
{
String nationalPrefix = GetNationalPrefix(element);
String nationalPrefixFormattingRule =
GetNationalPrefixFormattingRuleFromElement(element, nationalPrefix);
PhoneMetadata.Builder metadata =
LoadTerritoryTagMetadata(regionCode, element, nationalPrefix, nationalPrefixFormattingRule);
LoadAvailableFormats(metadata, regionCode, element, nationalPrefix.ToString(),
nationalPrefixFormattingRule.ToString(),
element.HasAttribute(NATIONAL_PREFIX_OPTIONAL_WHEN_FORMATTING));
LoadGeneralDesc(metadata, element);
return metadata.Build();
}
示例6: LoadAvailableFormats
/**
* Extracts the available formats from the provided DOM element. If it does not contain any
* nationalPrefixFormattingRule, the one passed-in is retained. The nationalPrefix,
* nationalPrefixFormattingRule and nationalPrefixOptionalWhenFormatting values are provided from
* the parent (territory) element.
*/
// @VisibleForTesting
public static void LoadAvailableFormats(PhoneMetadata.Builder metadata, String regionCode,
XmlElement element, String nationalPrefix,
String nationalPrefixFormattingRule,
bool nationalPrefixOptionalWhenFormatting)
{
String carrierCodeFormattingRule = "";
if (element.HasAttribute(CARRIER_CODE_FORMATTING_RULE))
{
carrierCodeFormattingRule = ValidateRE(
GetDomesticCarrierCodeFormattingRuleFromElement(element, nationalPrefix));
}
var numberFormatElements = element.GetElementsByTagName(NUMBER_FORMAT);
bool hasExplicitIntlFormatDefined = false;
int numOfFormatElements = numberFormatElements.Count;
if (numOfFormatElements > 0)
{
foreach (XmlElement numberFormatElement in numberFormatElements)
{
var format = new NumberFormat.Builder();
if (numberFormatElement.HasAttribute(NATIONAL_PREFIX_FORMATTING_RULE))
{
format.SetNationalPrefixFormattingRule(
GetNationalPrefixFormattingRuleFromElement(numberFormatElement, nationalPrefix));
format.SetNationalPrefixOptionalWhenFormatting(
numberFormatElement.HasAttribute(NATIONAL_PREFIX_OPTIONAL_WHEN_FORMATTING));
}
else
{
format.SetNationalPrefixFormattingRule(nationalPrefixFormattingRule);
format.SetNationalPrefixOptionalWhenFormatting(nationalPrefixOptionalWhenFormatting);
}
if (numberFormatElement.HasAttribute("carrierCodeFormattingRule"))
{
format.SetDomesticCarrierCodeFormattingRule(ValidateRE(
GetDomesticCarrierCodeFormattingRuleFromElement(
numberFormatElement, nationalPrefix)));
}
else
{
format.SetDomesticCarrierCodeFormattingRule(carrierCodeFormattingRule);
}
// Extract the pattern for the national format.
String nationalFormat =
LoadNationalFormat(metadata, numberFormatElement, format);
metadata.AddNumberFormat(format);
if (LoadInternationalFormat(metadata, numberFormatElement, nationalFormat))
{
hasExplicitIntlFormatDefined = true;
}
}
// Only a small number of regions need to specify the intlFormats in the xml. For the majority
// of countries the intlNumberFormat metadata is an exact copy of the national NumberFormat
// metadata. To minimize the size of the metadata file, we only keep intlNumberFormats that
// actually differ in some way to the national formats.
if (!hasExplicitIntlFormatDefined)
{
metadata.ClearIntlNumberFormat();
}
}
}
示例7: GetNationalPrefix
/**
* Returns the national prefix of the provided country element.
*/
// @VisibleForTesting
public static String GetNationalPrefix(XmlElement element)
{
return element.HasAttribute(NATIONAL_PREFIX) ? element.GetAttribute(NATIONAL_PREFIX) : "";
}
示例8: TryGetAttributeString
public bool TryGetAttributeString(XmlElement node, string name, out string val)
{
val = string.Empty;
if (!node.HasAttribute(name))
return false;
val = node.GetAttribute(name);
return true;
}
示例9: TryGetAttributeInt32
public bool TryGetAttributeInt32(XmlElement node, string name, out int val)
{
val = 0;
if (!node.HasAttribute(name))
return false;
string s = node.GetAttribute(name);
return int.TryParse(s, out val);
}
示例10: TryGetAttributeInt64
public bool TryGetAttributeInt64(XmlElement node, string name, out long val)
{
val = 0L;
if (!node.HasAttribute(name))
return false;
string s = node.GetAttribute(name);
return long.TryParse(s, out val);
}
示例11: TryGetAttributeBoolean
public bool TryGetAttributeBoolean(XmlElement node, string name, out bool val)
{
val = false;
if(!node.HasAttribute(name))
return false;
string s = node.GetAttribute(name);
return bool.TryParse(s, out val);
}
示例12: HasAttribute
/// <summary>
/// Determines if has attribute the specified element attrName.
/// </summary>
/// <returns><c>true</c> if has attribute the specified element attrName; otherwise, <c>false</c>.</returns>
/// <param name="element">Element.</param>
/// <param name="attrName">Attr name.</param>
public static bool HasAttribute(XmlElement element, string attrName)
{
if (null != element)
{
return element.HasAttribute(attrName);
}
return false;
}
示例13: GetStringValue
/// <summary>
/// Gets the attribute value by speified Xml Element and attribute name.
/// </summary>
/// <returns>The attribute value.</returns>
/// <param name="element">Element.</param>
/// <param name="attrName">Attr name.</param>
public static string GetStringValue(XmlElement element, string attrName)
{
if (null != element && element.HasAttribute(attrName))
{
return element.GetAttribute(attrName);
}
return null;
}