本文整理汇总了C#中System.Xml.XmlElement.HasAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XmlElement.HasAttribute方法的具体用法?C# XmlElement.HasAttribute怎么用?C# XmlElement.HasAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlElement
的用法示例。
在下文中一共展示了XmlElement.HasAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Tuple
public Tuple(XmlElement elTuple)
{
XmlNodeList l = elTuple.GetElementsByTagName("field");
fields = new Field[l.Count];
for (int i = 0; i < l.Count; i++)
{
XmlElement elField = (XmlElement) l[i];
fields[i] = new Field(elField);
}
if (elTuple.HasAttribute("id"))
{
tupleID = new TupleID(elTuple.GetAttribute("id"));
}
if (elTuple.HasAttribute("creationTimestamp"))
{
creationTimestamp = long.Parse(elTuple.GetAttribute("creationTimestamp"));
}
if (elTuple.HasAttribute("lastModificationTimestamp"))
{
lastModificationTimestamp = long.Parse(elTuple.GetAttribute("lastModificationTimestamp"));
}
if (elTuple.HasAttribute("expiration"))
{
expiration = long.Parse(elTuple.GetAttribute("expiration"));
}
}
示例2: ColorFromXML
private Color ColorFromXML(XmlElement xmlElement)
{
if (xmlElement.HasAttribute("ColorName"))
{
return Color.FromName(xmlElement.GetAttribute("ColorName"));
}
else if (xmlElement.HasAttribute("Color"))
{
string clr = xmlElement.GetAttribute("Color");
if (clr.Length == 7 && clr[0] =='#')
{
// RGB
int r = int.Parse(clr.Substring(1, 2), System.Globalization.NumberStyles.HexNumber);
int g = int.Parse(clr.Substring(3, 2), System.Globalization.NumberStyles.HexNumber);
int b = int.Parse(clr.Substring(5, 2), System.Globalization.NumberStyles.HexNumber);
return Color.FromArgb(r, g, b);
}
else if (clr.Length == 9 && clr[0] == '#')
{
// RGB
int a = int.Parse(clr.Substring(1, 2), System.Globalization.NumberStyles.HexNumber);
int r = int.Parse(clr.Substring(3, 2), System.Globalization.NumberStyles.HexNumber);
int g = int.Parse(clr.Substring(5, 2), System.Globalization.NumberStyles.HexNumber);
int b = int.Parse(clr.Substring(7, 2), System.Globalization.NumberStyles.HexNumber);
return Color.FromArgb(a, r, g, b);
}
}
throw new Exception("Unknown colour XML");
}
示例3: ProcessSetProperty
public static void ProcessSetProperty(XmlElement actionElement, IBlockWeb containerWeb, string blockId)
{
string connectorKey = actionElement.GetAttribute("connectorKey");
object value = ObjectReader.ReadObject(actionElement);
bool createConnector = false;
if (actionElement.HasAttribute("create") && actionElement.GetAttribute("create") == "true")
{
createConnector = true;
}
if (actionElement.HasAttribute("blockId"))
{
string aBlockId = actionElement.GetAttribute("blockId");
if (createConnector)
{
containerWeb[aBlockId].ProcessRequest("ProcessMetaService", BlockMetaServiceType.CreateConnector, connectorKey, null);
}
containerWeb[aBlockId][connectorKey].AttachEndPoint(value);
}
else
{
if (createConnector)
{
containerWeb[blockId].ProcessRequest("ProcessMetaService", BlockMetaServiceType.CreateConnector, connectorKey, null);
}
containerWeb[blockId][connectorKey].AttachEndPoint(value);
}
}
示例4: Sequence
public Sequence(string unit, XmlElement e)
{
string srcOverride = e.GetAttribute("src");
Name = e.GetAttribute("name");
sprites = SpriteSheetBuilder.LoadAllSprites(string.IsNullOrEmpty(srcOverride) ? unit : srcOverride );
start = int.Parse(e.GetAttribute("start"));
if (e.GetAttribute("length") == "*" || e.GetAttribute("end") == "*")
length = sprites.Length - Start;
else if (e.HasAttribute("length"))
length = int.Parse(e.GetAttribute("length"));
else if (e.HasAttribute("end"))
length = int.Parse(e.GetAttribute("end")) - int.Parse(e.GetAttribute("start"));
else
length = 1;
if( e.HasAttribute( "facings" ) )
facings = int.Parse( e.GetAttribute( "facings" ) );
else
facings = 1;
if (e.HasAttribute("tick"))
tick = int.Parse(e.GetAttribute("tick"));
else
tick = 40;
}
示例5: GetValue
public override string GetValue(XmlElement element, Context context)
{
if(element != null)
{
if (element.HasAttribute(Name, string.Empty))
{
return element.GetAttribute(Name);
}
else if (element.HasAttribute(Name, ResourceManager.VariableNamespace))
{
IValueNode value = (IValueNode)context.GetVariable(element.GetAttribute(Name, ResourceManager.VariableNamespace));
value.InitNewState(context);
return value.Value;
}
else
{
XmlElement valueNode = element[element.Name + "." + Name];
if (valueNode != null)
{
IValueNode value = (IValueNode)SequenceFactory.Instance.CreateChildrenAsSequence(valueNode, context);
value.InitNewState(context);
return value.Value;
}
}
}
return null;
}
示例6: ReadFromXmlElement
private void ReadFromXmlElement(XmlElement el)
{
if (el.HasAttribute("Value"))
value = uint.Parse(el.GetAttribute("Value"));
if (el.HasAttribute("Name"))
name = el.GetAttribute("Name");
}
示例7: ProjectDescriptor
/// <summary>
/// Creates a project descriptor for the project node specified by the xml element.
/// </summary>
/// <param name="element">The <Project> node of the xml template file.</param>
/// <param name="hintPath">The directory on which relative paths (e.g. for referenced files) are based.</param>
public ProjectDescriptor(XmlElement element, string hintPath)
{
if (element == null)
throw new ArgumentNullException("element");
if (hintPath == null)
throw new ArgumentNullException("hintPath");
if (element.HasAttribute("name")) {
name = element.GetAttribute("name");
} else {
name = "${ProjectName}";
}
if (element.HasAttribute("directory")) {
relativePath = element.GetAttribute("directory");
} else {
relativePath = ".";
}
languageName = element.GetAttribute("language");
if (string.IsNullOrEmpty(languageName)) {
ProjectTemplate.WarnAttributeMissing(element, "language");
}
defaultPlatform = element.GetAttribute("defaultPlatform");
LoadElementChildren(element, hintPath);
}
示例8: Parse
public static new Inform Parse(XmlElement inform)
{
if (inform == null)
{
throw new Exception("parameter can't be null!");
}
string type = string.Empty;
string operation = string.Empty;
if (inform.HasAttribute("Type"))
{
type = inform.GetAttribute("Type");
}
else
{
throw new Exception("load hasn't type attribute!");
}
if (inform.HasAttribute("Operation"))
{
operation = inform.GetAttribute("Operation");
}
else
{
throw new Exception("parameter hasn't Operation attribute!");
}
Operation enumOperation = (Operation)Enum.Parse(typeof(Operation), operation);
Inform result = new Inform(enumOperation, inform.Name, type, inform.InnerText);
return result;
}
示例9: ParseXml
internal override void ParseXml(XmlElement xml)
{
base.ParseXml(xml);
foreach (XmlNode child in xml.ChildNodes)
{
string name = child.Name;
if (string.Compare(name, "ShapeRepresentations") == 0)
{
List<IfcShapeModel> shapes = new List<IfcShapeModel>(child.ChildNodes.Count);
foreach (XmlNode cn in child.ChildNodes)
{
IfcShapeModel s = mDatabase.ParseXml<IfcShapeModel>(cn as XmlElement);
if (s != null)
shapes.Add(s);
}
ShapeRepresentations = shapes;
}
else if (string.Compare(name, "PartOfProductDefinitionShape") == 0)
PartOfProductDefinitionShape = mDatabase.ParseXml<IfcProductRepresentationSelect>(child as XmlElement);
}
if (xml.HasAttribute("Name"))
Name = xml.Attributes["Name"].Value;
if (xml.HasAttribute("Description"))
Description = xml.Attributes["Description"].Value;
if (xml.HasAttribute("ProductDefinitional"))
Enum.TryParse<IfcLogicalEnum>(xml.Attributes["ProductDefinitional"].Value,true, out mProductDefinitional);
}
示例10: Span
/// <summary>
/// Initializes a new instance of the <see cref="Span"/> class.
/// </summary>
/// <param name="span">The XML element that describes the span.</param>
public Span(XmlElement span)
{
color = new HighlightColor(span);
if (span.HasAttribute("rule"))
rule = span.GetAttribute("rule");
if (span.HasAttribute("escapecharacter"))
escapeCharacter = span.GetAttribute("escapecharacter")[0];
name = span.GetAttribute("name");
if (span.HasAttribute("stopateol"))
stopEOL = Boolean.Parse(span.GetAttribute("stopateol"));
begin = span["Begin"].InnerText.ToCharArray();
beginColor = new HighlightColor(span["Begin"], color);
if (span["Begin"].HasAttribute("singleword"))
isBeginSingleWord = Boolean.Parse(span["Begin"].GetAttribute("singleword"));
if (span["Begin"].HasAttribute("startofline"))
isBeginStartOfLine = Boolean.Parse(span["Begin"].GetAttribute("startofline"));
if (span["End"] != null)
{
end = span["End"].InnerText.ToCharArray();
endColor = new HighlightColor(span["End"], color);
if (span["End"].HasAttribute("singleword"))
isEndSingleWord = Boolean.Parse(span["End"].GetAttribute("singleword"));
}
}
示例11: ReadFromXmlElement
public void ReadFromXmlElement(XmlElement el)
{
if (el.HasAttribute("Name"))
name = el.GetAttribute("Name");
if (el.HasAttribute("Value"))
value = el.GetAttribute("Value");
}
示例12: Load
public override void Load (XmlElement element)
{
//GetAttribute returns String.Empty even if the attr does not exist
//but we want null (empty attribute is significant), so do an extra check
if (element.HasAttribute ("PermittedCreationPaths"))
permittedCreationPaths = element.GetAttribute("PermittedCreationPaths").Split (':');
if (element.HasAttribute ("ExcludedCreationPaths"))
excludedCreationPaths = element.GetAttribute("ExcludedCreationPaths").Split (':');
if (element.HasAttribute ("RequiredFiles"))
requiredFiles = element.GetAttribute("RequiredFiles").Split (':');
if (element.HasAttribute ("ExcludedFiles"))
excludedFiles = element.GetAttribute("ExcludedFiles").Split (':');
if (element.HasAttribute ("ProjectType"))
projectType = element.GetAttribute("ProjectType");
string requireExistsStr = element.GetAttribute ("RequireProject");
if (!string.IsNullOrEmpty (requireExistsStr)) {
try {
requireExists = bool.Parse (requireExistsStr);
} catch (FormatException) {
throw new InvalidOperationException ("Invalid value for RequireExists in template.");
}
}
}
示例13: ParseXml
public static Attempt ParseXml(XmlElement node)
{
var newTime = Time.FromXml(node);
var index = int.Parse(node.Attributes["id"].InnerText, CultureInfo.InvariantCulture);
AtomicDateTime? started = null;
var startedSynced = false;
AtomicDateTime? ended = null;
var endedSynced = false;
if (node.HasAttribute("started"))
{
var startedTime = DateTime.Parse(node.Attributes["started"].InnerText, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
if (node.HasAttribute("isStartedSynced"))
startedSynced = bool.Parse(node.Attributes["isStartedSynced"].InnerText);
started = new AtomicDateTime(startedTime, startedSynced);
}
if (node.HasAttribute("ended"))
{
var endedTime = DateTime.Parse(node.Attributes["ended"].InnerText, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
if (node.HasAttribute("isEndedSynced"))
endedSynced = bool.Parse(node.Attributes["isEndedSynced"].InnerText);
ended = new AtomicDateTime(endedTime, endedSynced);
}
return new Attempt(index, newTime, started, ended);
}
示例14: ParseXml
internal override void ParseXml(XmlElement xml)
{
base.ParseXml(xml);
if (xml.HasAttribute("CoordinateSpaceDimension"))
CoordinateSpaceDimension = int.Parse(xml.Attributes["CoordinateSpaceDimension"].Value);
if (xml.HasAttribute("Precision"))
Precision = double.Parse(xml.Attributes["Precision"].Value);
foreach (XmlNode child in xml.ChildNodes)
{
string name = child.Name;
if (string.Compare(name, "WorldCoordinateSystem") == 0)
WorldCoordinateSystem = mDatabase.ParseXml<IfcAxis2Placement3D>(child as XmlElement);
else if (string.Compare(name, "TrueNorth") == 0)
TrueNorth = mDatabase.ParseXml<IfcDirection>(child as XmlElement);
else if (string.Compare(name, "HasSubContexts") == 0)
{
List<IfcGeometricRepresentationSubContext> subs = new List<IfcGeometricRepresentationSubContext>();
foreach (XmlNode node in child.ChildNodes)
{
IfcGeometricRepresentationSubContext sub = mDatabase.ParseXml<IfcGeometricRepresentationSubContext>(node as XmlElement);
if (sub != null)
sub.ContainerContext = this;
}
}
else if (string.Compare(name, "HasCoordinateOperation") == 0)
HasCoordinateOperation = mDatabase.ParseXml<IfcCoordinateOperation>(child as XmlElement);
}
}
示例15: ProcessStatement
protected bool ProcessStatement(XmlElement element, IXmlProcessorEngine engine)
{
if (!element.HasAttribute(DefinedAttrName) &&
!element.HasAttribute(NotDefinedAttrName))
{
throw new XmlProcessorException("'if' elements expects a non empty defined or not-defined attribute");
}
if (element.HasAttribute(DefinedAttrName) &&
element.HasAttribute(NotDefinedAttrName))
{
throw new XmlProcessorException("'if' elements expects a non empty defined or not-defined attribute");
}
bool processContents = false;
if (element.HasAttribute(DefinedAttrName))
{
processContents = engine.HasFlag(element.GetAttribute(DefinedAttrName));
}
else
{
processContents = !engine.HasFlag(element.GetAttribute(NotDefinedAttrName));
}
return processContents;
}