本文整理汇总了C#中System.Xml.XmlElement.SetAttributeNode方法的典型用法代码示例。如果您正苦于以下问题:C# XmlElement.SetAttributeNode方法的具体用法?C# XmlElement.SetAttributeNode怎么用?C# XmlElement.SetAttributeNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlElement
的用法示例。
在下文中一共展示了XmlElement.SetAttributeNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: saveToFile
protected virtual XmlElement saveToFile(XmlDocument doc, XmlElement root)
{
XmlAttribute name = doc.CreateAttribute(PetriXmlHelper.XML_BASEITEM_NAMESPACE_PREFIX, "name", PetriXmlHelper.XML_BASEITEM_NAMESPACE);
name.Value = this.name;
root.SetAttributeNode(name);
XmlAttribute unid = doc.CreateAttribute(PetriXmlHelper.XML_BASEITEM_NAMESPACE_PREFIX, "unid", PetriXmlHelper.XML_BASEITEM_NAMESPACE);
unid.Value = this.unid.ToString();
root.SetAttributeNode(unid);
XmlAttribute showAnnotation = doc.CreateAttribute(PetriXmlHelper.XML_BASEITEM_NAMESPACE_PREFIX, "showannotation", PetriXmlHelper.XML_BASEITEM_NAMESPACE);
showAnnotation.Value = this.showAnnotation.ToString();
root.SetAttributeNode(showAnnotation);
return root;
}
示例2: writeItemData
protected XmlElement writeItemData(XmlDocument doc, XmlElement root)
{
XmlAttribute name = doc.CreateAttribute(PetriXmlHelper.XML_BASEITEM_NAMESPACE_PREFIX, AbstractItem.XML_NAME, PetriXmlHelper.XML_BASEITEM_NAMESPACE);
name.Value = this.name;
root.SetAttributeNode(name);
XmlAttribute unid = doc.CreateAttribute(PetriXmlHelper.XML_BASEITEM_NAMESPACE_PREFIX, AbstractItem.XML_UNID, PetriXmlHelper.XML_BASEITEM_NAMESPACE);
unid.Value = this.unid.ToString();
root.SetAttributeNode(unid);
XmlAttribute showAnnotation = doc.CreateAttribute(PetriXmlHelper.XML_BASEITEM_NAMESPACE_PREFIX, AbstractItem.XML_SHOWANNOTATION, PetriXmlHelper.XML_BASEITEM_NAMESPACE);
showAnnotation.Value = this.showAnnotation.ToString();
root.SetAttributeNode(showAnnotation);
return root;
}
示例3: CreateAndAppendAttribute
public static XmlAttribute CreateAndAppendAttribute(XmlElement parent, string name, string value)
{
XmlAttribute xAttribute = parent.OwnerDocument.CreateAttribute(name);
if (value != String.Empty)
xAttribute.Value = value;
parent.SetAttributeNode(xAttribute);
return xAttribute;
}
示例4: saveToFile
protected override XmlElement saveToFile(XmlDocument doc, XmlElement root)
{
base.saveToFile(doc, root);
XmlAttribute attachedItem = doc.CreateAttribute(PetriXmlHelper.XML_NOTE_NAMESPACE_PREFIX, "attachedItem", PetriXmlHelper.XML_NOTE_NAMESPACE);
attachedItem.Value = this.attachedItem.Unid.ToString();
root.SetAttributeNode(attachedItem);
XmlElement text = doc.CreateElement(PetriXmlHelper.XML_NOTE_NAMESPACE_PREFIX, "Text", PetriXmlHelper.XML_NOTE_NAMESPACE);
text.InnerText = this.text;
root.AppendChild(text);
return root;
}
示例5: Init
public void Init()
{
base.Init();
elementCreator=new GraphConnectorElementCreator(xmiDocument,documentBuilder);
parentElement=GraphNodeElementStub.CreateGraphNodeElementStub(xmiDocument);
graphEdgeElement=GraphEdgeElementStub.CreateGraphEdgeElementStub(xmiDocument);
XmlAttribute idAttr=xmiDocument.CreateAttribute("xmi","id",XmiElements.XMI_NAMESPACE_URI);
idAttr.Value=GRAPH_EDGE_ELEMENT_ID;
graphEdgeElement.SetAttributeNode(idAttr);
//graphEdgeElement.SetAttribute(XmiElements.XMI_ID_ATTR_NAME,XmiElements.XMI_NAMESPACE_URI,GRAPH_EDGE_ELEMENT_ID);
}
示例6: AddAttributeNode
public XmlAttribute AddAttributeNode(XmlElement node, string name, string value)
{
XmlAttribute a = xmlDoc.CreateAttribute(name);
a.Value = value;
if (node == null)
xmlDoc.DocumentElement.SetAttributeNode(a);
else
node.SetAttributeNode(a);
return a;
}
示例7: saveToFile
protected override XmlElement saveToFile(XmlDocument doc, XmlElement root)
{
base.saveToFile(doc, root);
root.AppendChild(PetriXmlHelper.savePointF(doc, this.point, "TopLeftPoint"));
root.AppendChild(PetriXmlHelper.savePointF(doc, this.origo, "Origo"));
root.AppendChild(PetriXmlHelper.savePointF(doc, this.labelOffset, "LabelOffset"));
root.AppendChild(PetriXmlHelper.saveSizeF(doc, this.size, "Size"));
XmlAttribute radius = doc.CreateAttribute(PetriXmlHelper.XML_ITEM_NAMESPACE_PREFIX, "radius", PetriXmlHelper.XML_ITEM_NAMESPACE);
radius.Value = this.radius.ToString();
root.SetAttributeNode(radius);
return root;
}
示例8: saveToFile
protected override XmlElement saveToFile(XmlDocument doc, XmlElement root)
{
base.saveToFile(doc, root);
root.AppendChild(PetriXmlHelper.savePointF(doc, this.clockOffset, "ClockOffset"));
XmlAttribute angle = doc.CreateAttribute(PetriXmlHelper.XML_TRANSITION_NAMESPACE_PREFIX, "angle", PetriXmlHelper.XML_TRANSITION_NAMESPACE);
angle.Value = this.angle.ToString();
root.SetAttributeNode(angle);
XmlAttribute priority = doc.CreateAttribute(PetriXmlHelper.XML_TRANSITION_NAMESPACE_PREFIX, "priority", PetriXmlHelper.XML_TRANSITION_NAMESPACE);
priority.Value = this.priority.ToString();
root.SetAttributeNode(priority);
XmlAttribute transitionType = doc.CreateAttribute(PetriXmlHelper.XML_TRANSITION_NAMESPACE_PREFIX, "type", PetriXmlHelper.XML_TRANSITION_NAMESPACE);
transitionType.Value = this.transitionType.Value;
root.SetAttributeNode(transitionType);
XmlAttribute delay = doc.CreateAttribute(PetriXmlHelper.XML_TRANSITION_NAMESPACE_PREFIX, "delay", PetriXmlHelper.XML_TRANSITION_NAMESPACE);
delay.Value = this.delay.ToString();
root.SetAttributeNode(delay);
XmlAttribute clockRadius = doc.CreateAttribute(PetriXmlHelper.XML_TRANSITION_NAMESPACE_PREFIX, "clockRadius", PetriXmlHelper.XML_TRANSITION_NAMESPACE);
clockRadius.Value = this.clockRadius.ToString();
root.SetAttributeNode(clockRadius);
return root;
}
示例9: AddNamespaces
internal static void AddNamespaces(XmlElement elem, Hashtable namespaces)
{
if (namespaces != null)
{
foreach (string str in namespaces.Keys)
{
if (!elem.HasAttribute(str))
{
XmlAttribute newAttr = elem.OwnerDocument.CreateAttribute(str);
newAttr.Value = namespaces[str] as string;
elem.SetAttributeNode(newAttr);
}
}
}
}
示例10: FixupNamespaceNodes
private void FixupNamespaceNodes (XmlElement src, XmlElement dst, bool ignoreDefault)
{
// add namespace nodes
foreach (XmlAttribute attr in src.SelectNodes ("namespace::*")) {
if (attr.LocalName == "xml")
continue;
if (ignoreDefault && attr.LocalName == "xmlns")
continue;
dst.SetAttributeNode (dst.OwnerDocument.ImportNode (attr, true) as XmlAttribute);
}
}
示例11: RecCompXML
/// <summary>
/// Used by CompressXML
/// </summary>
/// <param name="counts">Map of attribute to number of occurrences -- could be used to improve algorithm</param>
/// <param name="entities">Map of attribute to entity name</param>
/// <param name="doc"></param>
/// <param name="el"></param>
/// <param name="idx">Number that is incremented to provide new entity names</param>
private static void RecCompXML(Hashtable counts, Hashtable entities, XmlDocument doc, XmlElement el, ref int idx)
{
ArrayList keys = new ArrayList();
foreach(XmlAttribute att in el.Attributes)
{
//don't try to do anything with xmlns nodes.
if (att.Name.IndexOf("xmlns") == -1)
keys.Add(att.Name);
}
foreach(string s in keys)
{
string val = el.Attributes[s].Value;
if (counts[val] == null)
{
counts[val] = 1;
}
else
{
counts[val] = (int)counts[val] + 1;
}
if (val.Length > 30)
{
string entname;
if(entities[val] == null)
{
idx += 1;
entname = "E"+idx.ToString();
entities[val] = entname;
}
else
{
entname = (string)entities[val];
}
XmlAttribute attr;
//xlinks are a special case at the moment as the .NET XML API requires whatever bit of code
//outputs a qualified name to *just magically happen to know* the URI that the prefix refers to.
if (s.IndexOf("xlink") == 0)
{
attr = doc.CreateAttribute(s, "http://www.w3.org/1999/xlink");
}
else
{
attr = doc.CreateAttribute(s);
}
attr.AppendChild(doc.CreateEntityReference(entname));
el.SetAttributeNode(attr);
}
}
foreach(XmlNode ch in el.ChildNodes)
{
if (ch.GetType() == typeof(XmlElement))
RecCompXML(counts, entities, doc, (XmlElement)ch, ref idx);
}
}
示例12: RecCompXML
/// <summary>
/// Used by CompressXML
/// </summary>
/// <param name="counts">Map of attribute to number of occurrences -- could be used to improve algorithm</param>
/// <param name="entities">Map of attribute to entity name</param>
/// <param name="doc"></param>
/// <param name="el"></param>
/// <param name="idx">Number that is incremented to provide new entity names</param>
private static void RecCompXML(Hashtable counts, Hashtable entities, XmlDocument doc, XmlElement el, ref int idx)
{
ArrayList keys = new ArrayList();
foreach(XmlAttribute att in el.Attributes)
{
keys.Add(att.Name);
}
foreach(string s in keys)
{
string val = el.Attributes[s].Value;
if (counts[val] == null)
{
counts[val] = 1;
}
else
{
counts[val] = (int)counts[val] + 1;
}
if (val.Length > 30)
{
string entname;
if(entities[val] == null)
{
idx += 1;
entname = "E"+idx.ToString();
entities[val] = entname;
}
else
{
entname = (string)entities[val];
}
XmlAttribute attr = doc.CreateAttribute(s);
attr.AppendChild(doc.CreateEntityReference(entname));
el.SetAttributeNode(attr);
}
}
foreach(XmlNode ch in el.ChildNodes)
{
if (ch.GetType() == typeof(XmlElement))
RecCompXML(counts, entities, doc, (XmlElement)ch, ref idx);
}
}
示例13: AddNamespaces
internal static void AddNamespaces (XmlElement elem, CanonicalXmlNodeList namespaces) {
if (namespaces != null) {
foreach (XmlNode attrib in namespaces) {
string name = ((attrib.Prefix.Length > 0) ? attrib.Prefix + ":" + attrib.LocalName : attrib.LocalName);
// Skip the attribute if one with the same qualified name already exists
if (elem.HasAttribute(name) || (name.Equals("xmlns") && elem.Prefix.Length == 0)) continue;
XmlAttribute nsattrib = (XmlAttribute) elem.OwnerDocument.CreateAttribute(name);
nsattrib.Value = attrib.Value;
elem.SetAttributeNode(nsattrib);
}
}
}
示例14: SetAttribute
private void SetAttribute(XmlElement element, string nsuri, string prefix, string localname, string val)
{
XmlAttribute attr = doc.CreateAttribute(prefix, localname, nsuri);
attr.Value = val;
element.SetAttributeNode(attr);
}
示例15: FillNodeChildrenFromRow
private void FillNodeChildrenFromRow (DataRow row, XmlElement element)
{
DataTable table = row.Table;
// fill columns for the row
for (int i = 0; i < table.Columns.Count; i++) {
DataColumn col = table.Columns [i];
string value = row.IsNull (col) ? String.Empty : row [col].ToString ();
switch (col.ColumnMapping) {
case MappingType.Element:
XmlElement el = CreateElement (col.Prefix, XmlHelper.Encode (col.ColumnName), col.Namespace);
el.InnerText = value;
element.AppendChild (el);
break;
case MappingType.Attribute:
XmlAttribute attr = CreateAttribute (col.Prefix, XmlHelper.Encode (col.ColumnName), col.Namespace);
attr.Value = value;
element.SetAttributeNode (attr);
break;
case MappingType.SimpleContent:
XmlText text = CreateTextNode (value);
element.AppendChild (text);
break;
// FIXME: how to handle hidden?
}
}
}