本文整理汇总了C#中System.Xml.XmlDocument.CreateAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CreateAttribute方法的具体用法?C# XmlDocument.CreateAttribute怎么用?C# XmlDocument.CreateAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CreateAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRssFiles
private void GetRssFiles()
{
XmlDocument xdoc = new XmlDocument();
XmlElement xRoot = xdoc.CreateElement("Data");
xdoc.AppendChild(xRoot);
string[] colFileInfos = Directory.GetFiles(Server.MapPath("~/UI/RSS/Categories"), "*.xml", SearchOption.AllDirectories);
for (int i = 0; i < colFileInfos.Length; i++)
{
XmlElement xRow = xdoc.CreateElement("File");
xRoot.AppendChild(xRow);
XmlAttribute xAttpath = xdoc.CreateAttribute("Path");
xRow.Attributes.Append(xAttpath);
XmlAttribute xAttname = xdoc.CreateAttribute("Name");
xRow.Attributes.Append(xAttname);
xAttname.Value = colFileInfos[i].Substring(colFileInfos[i].LastIndexOf('\\') + 1, colFileInfos[i].Length - colFileInfos[i].LastIndexOf('\\') - 1).Replace("rss", "").Replace("-", "").Replace(".xml", "").Replace("//", "/");
xAttpath.Value ="change me" + "/UI/RSS/Categories" + colFileInfos[i].Substring(colFileInfos[i].LastIndexOf('\\'), colFileInfos[i].Length - colFileInfos[i].LastIndexOf('\\')).Replace("//", "/");
}
XslTemplate xsl = XslTemplateManager.GetByID(XSLID);
if (null == xsl)
return;
dvData.InnerHtml = UtilitiesManager.TransformXMLWithXSLText(xdoc.OuterXml, xsl.Details);
}
示例2: btn_OK_Click
private void btn_OK_Click(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
xmlDoc.AppendChild(docNode);
XmlNode version = xmlDoc.CreateElement("version");
xmlDoc.AppendChild(version);
XmlNode sbtNode = xmlDoc.CreateElement("SBT");
XmlAttribute sbtAttribute = xmlDoc.CreateAttribute("Path");
sbtAttribute.Value = textBox1.Text;
sbtNode.Attributes.Append(sbtAttribute);
version.AppendChild(sbtNode);
XmlNode garenaNode = xmlDoc.CreateElement("Garena");
XmlAttribute garenaAttribute = xmlDoc.CreateAttribute("Path");
garenaAttribute.Value = textBox2.Text;
garenaNode.Attributes.Append(garenaAttribute);
version.AppendChild(garenaNode);
XmlNode superNode = xmlDoc.CreateElement("Super");
XmlAttribute superAttribute = xmlDoc.CreateAttribute("Path");
superAttribute.Value = textBox3.Text;
superNode.Attributes.Append(superAttribute);
version.AppendChild(superNode);
xmlDoc.Save("path");
this.Close();
}
示例3: ToText
public override string ToText(Subtitle subtitle, string title)
{
string xmlStructure =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine +
"<transcript/>";
var xml = new XmlDocument();
xml.LoadXml(xmlStructure);
foreach (Paragraph p in subtitle.Paragraphs)
{
XmlNode paragraph = xml.CreateElement("text");
XmlAttribute start = xml.CreateAttribute("start");
start.InnerText = string.Format("{0}", p.StartTime.TotalMilliseconds / 1000).Replace(",", ".");
paragraph.Attributes.Append(start);
XmlAttribute duration = xml.CreateAttribute("dur");
duration.InnerText = string.Format("{0}", p.Duration.TotalMilliseconds / 1000).Replace(",", ".");
paragraph.Attributes.Append(duration);
paragraph.InnerText = p.Text;
xml.DocumentElement.AppendChild(paragraph);
}
return ToUtf8XmlString(xml);
}
示例4: AddOrModifyAppSettings
static XmlDocument AddOrModifyAppSettings(XmlDocument xmlDoc, string key, string value)
{
bool isNew = false;
XmlNodeList list = xmlDoc.DocumentElement.SelectNodes(string.Format("appSettings/add[@key='{0}']", key));
XmlNode node;
isNew = list.Count == 0;
if (isNew)
{
node = xmlDoc.CreateNode(XmlNodeType.Element, "add", null);
XmlAttribute attribute = xmlDoc.CreateAttribute("key");
attribute.Value = key;
node.Attributes.Append(attribute);
attribute = xmlDoc.CreateAttribute("value");
attribute.Value = value;
node.Attributes.Append(attribute);
xmlDoc.DocumentElement.SelectNodes("appSettings")[0].AppendChild(node);
}
else
{
node = list[0];
node.Attributes["value"].Value = value;
}
return xmlDoc;
}
示例5: SaveToFile
public static string SaveToFile ()
{
string title;
string[] fragments;
XmlDocument doc;
XmlElement item;
XmlAttribute subject_attr, body_attr, contrib_attr;
fragments = subject.Split (' ');
title = null;
foreach (string s in fragments)
{
title += s;
}
doc = new XmlDocument ();
doc.AppendChild (doc.CreateProcessingInstruction ("xml", "version='1.0'"));
item = doc.CreateElement ("mwnitem");
subject_attr = doc.CreateAttribute ("subject");
subject_attr.Value = subject;
body_attr = doc.CreateAttribute ("body");
body_attr.Value = @body;
contrib_attr = doc.CreateAttribute ("contrib");
contrib_attr.Value = @contrib;
item.Attributes.Append (subject_attr);
item.Attributes.Append (body_attr);
item.Attributes.Append (contrib_attr);
doc.AppendChild (item);
doc.Save ((title = title.Substring (0, 8)) + ".mwnitem");
return title;
}
示例6: ToText
public override string ToText(Subtitle subtitle, string title)
{
// <Phrase TimeStart="4020" TimeEnd="6020">
// <Text>XYZ PRESENTS</Text>
// </Phrase>
string xmlStructure = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine + "<Subtitle xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"></Subtitle>";
XmlDocument xml = new XmlDocument();
xml.LoadXml(xmlStructure);
int id = 1;
foreach (Paragraph p in subtitle.Paragraphs)
{
XmlNode paragraph = xml.CreateElement("Phrase");
XmlAttribute start = xml.CreateAttribute("TimeStart");
start.InnerText = p.StartTime.TotalMilliseconds.ToString();
paragraph.Attributes.Append(start);
XmlAttribute duration = xml.CreateAttribute("TimeEnd");
duration.InnerText = p.EndTime.TotalMilliseconds.ToString();
paragraph.Attributes.Append(duration);
XmlNode text = xml.CreateElement("Text");
text.InnerText = HtmlUtil.RemoveHtmlTags(p.Text).Replace(Environment.NewLine, "\\n");
paragraph.AppendChild(text);
xml.DocumentElement.AppendChild(paragraph);
id++;
}
return ToUtf8XmlString(xml);
}
示例7: Merge
public static void Merge(XmlDocument doc)
{
var elements = new [] {
Tuple.Create("Default", "diff", "application/octet" ),
Tuple.Create("Default", "exe", "application/octet" ),
Tuple.Create("Default", "dll", "application/octet" ),
Tuple.Create("Default", "shasum", "text/plain" ),
};
var typesElement = doc.FirstChild.NextSibling;
if (typesElement.Name.ToLowerInvariant() != "types") {
throw new Exception("Invalid ContentTypes file, expected root node should be 'Types'");
}
var existingTypes = typesElement.ChildNodes.OfType<XmlElement>()
.Select(k => Tuple.Create(k.Name,
k.GetAttribute("Extension").ToLowerInvariant(),
k.GetAttribute("ContentType").ToLowerInvariant()));
var toAdd = elements
.Where(x => existingTypes.All(t => t.Item2 != x.Item2.ToLowerInvariant()))
.Select(element => {
var ret = doc.CreateElement(element.Item1, typesElement.NamespaceURI);
var ext = doc.CreateAttribute("Extension"); ext.Value = element.Item2;
var ct = doc.CreateAttribute("ContentType"); ct.Value = element.Item3;
ret.Attributes.Append(ext);
ret.Attributes.Append(ct);
return ret;
});
foreach (var v in toAdd) typesElement.AppendChild(v);
}
示例8: ToText
public override string ToText(Subtitle subtitle, string title)
{
string xmlStructure =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine +
"<USFSubtitles version=\"1.0\">" + Environment.NewLine +
@"<metadata>
<title>Universal Subtitle Format</title>
<author>
<name>SubtitleEdit</name>
<email>[email protected]</email>
<url>http://www.nikse.dk/</url>
</author>" + Environment.NewLine +
" <language code=\"eng\">English</language>" + Environment.NewLine +
@" <date>[DATE]</date>
<comment>This is a USF file</comment>
</metadata>
<styles>
<!-- Here we redefine the default style -->" + Environment.NewLine +
" <style name=\"Default\">" + Environment.NewLine +
" <fontstyle face=\"Arial\" size=\"24\" color=\"#FFFFFF\" back-color=\"#AAAAAA\" />" +
Environment.NewLine +
" <position alignment=\"BottomCenter\" vertical-margin=\"20%\" relative-to=\"Window\" />" +
@" </style>
</styles>
<subtitles>
</subtitles>
</USFSubtitles>";
xmlStructure = xmlStructure.Replace("[DATE]", DateTime.Now.ToString("yyyy-MM-dd"));
var xml = new XmlDocument();
xml.LoadXml(xmlStructure);
xml.DocumentElement.SelectSingleNode("metadata/title").InnerText = title;
var subtitlesNode = xml.DocumentElement.SelectSingleNode("subtitles");
foreach (Paragraph p in subtitle.Paragraphs)
{
XmlNode paragraph = xml.CreateElement("subtitle");
XmlAttribute start = xml.CreateAttribute("start");
start.InnerText = p.StartTime.ToString().Replace(",", ".");
paragraph.Attributes.Prepend(start);
XmlAttribute stop = xml.CreateAttribute("stop");
stop.InnerText = p.EndTime.ToString().Replace(",", ".");
paragraph.Attributes.Append(stop);
XmlNode text = xml.CreateElement("text");
text.InnerText = Utilities.RemoveHtmlTags(p.Text);
paragraph.AppendChild(text);
XmlAttribute style = xml.CreateAttribute("style");
style.InnerText = "Default";
text.Attributes.Append(style);
subtitlesNode.AppendChild(paragraph);
}
return ToUtf8XmlString(xml);
}
示例9: ToText
public override string ToText(Subtitle subtitle, string title)
{
string xmlStructure =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine +
"<tt>" + Environment.NewLine +
" <div>" + Environment.NewLine +
" </div>" + Environment.NewLine +
"</tt>";
var xml = new XmlDocument();
xml.LoadXml(xmlStructure);
XmlNode div = xml.DocumentElement.SelectSingleNode("div");
foreach (Paragraph p in subtitle.Paragraphs)
{
XmlNode paragraph = xml.CreateElement("p");
string text = HtmlUtil.RemoveHtmlTags(p.Text, true);
paragraph.InnerText = text;
paragraph.InnerXml = "<![CDATA[<sub>" + paragraph.InnerXml.Replace(Environment.NewLine, "<br />") + "</sub>]]>";
XmlAttribute start = xml.CreateAttribute("begin");
start.InnerText = ConvertToTimeString(p.StartTime);
paragraph.Attributes.Append(start);
XmlAttribute end = xml.CreateAttribute("end");
end.InnerText = ConvertToTimeString(p.EndTime);
paragraph.Attributes.Append(end);
div.AppendChild(paragraph);
}
return ToUtf8XmlString(xml);
}
示例10: AddEditInventoryItem
public static string AddEditInventoryItem(InventoryItem inventoryItem, string xmlFileName)
{
string success = "ono";
try
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(xmlFileName);
XmlNode InventoryNode = xdoc.SelectSingleNode("//Inventory");
XmlNode InventoryItemNode;
if (inventoryItem.ItemId == null)
{
InventoryItemNode = xdoc.CreateElement("Item");
inventoryItem.ItemId = Guid.NewGuid().ToString();
XmlAttribute ItemId = xdoc.CreateAttribute("Id"); ItemId.InnerText = inventoryItem.ItemId; InventoryItemNode.Attributes.Append(ItemId);
XmlAttribute ItemType = xdoc.CreateAttribute("Type"); ItemType.InnerText = inventoryItem.ItemType; InventoryItemNode.Attributes.Append(ItemType);
XmlAttribute Desc = xdoc.CreateAttribute("Desc"); Desc.InnerText = inventoryItem.ItemDesc; InventoryItemNode.Attributes.Append(Desc);
XmlAttribute Location = xdoc.CreateAttribute("Location"); Location.InnerText = inventoryItem.ItemLoc; InventoryItemNode.Attributes.Append(Location);
XmlAttribute ItemDetail = xdoc.CreateAttribute("ItemDetail"); ItemDetail.InnerText = inventoryItem.ItemDetail; InventoryItemNode.Attributes.Append(ItemDetail);
InventoryNode.AppendChild(InventoryItemNode);
}
else
{
InventoryItemNode = xdoc.SelectSingleNode("//Inventory//Item[@Id='" + inventoryItem.ItemId + "']");
InventoryItemNode.Attributes["Type"].InnerText = inventoryItem.ItemType;
InventoryItemNode.Attributes["Desc"].InnerText = inventoryItem.ItemDesc;
InventoryItemNode.Attributes["Location"].InnerText = inventoryItem.ItemLoc;
InventoryItemNode.Attributes["ItemDetail"].InnerText = inventoryItem.ItemDetail;
}
xdoc.Save(xmlFileName);
success = "ok";
}
catch (Exception ex) { success = "ERROR: " + ex.Message; }
return success;
}
示例11: AddNodeToXml1
public void AddNodeToXml1(string xmlFile)
{
//加载xml文件,并选出要添加子节点的节点
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlFile);//不会覆盖原有内容
//xmlDoc.LoadXml("<Settings><Set></Set></Settings>");//会覆盖原有内容
XmlNode parentNode = xmlDoc.SelectSingleNode(@"Settings/Set");
//创建节点,并设置节点属性
XmlElement addNode = xmlDoc.CreateElement("Log");
XmlAttribute addNodeName = xmlDoc.CreateAttribute("Name");
addNodeName.InnerText = "全方位日志2";
XmlAttribute addNodeUrl = xmlDoc.CreateAttribute("Url");
addNodeUrl.InnerText = @"E:\vmware_linux_file\test\Working\TianJin\log2";
XmlAttribute addNodeSaveDays = xmlDoc.CreateAttribute("SaveDays");
addNodeSaveDays.InnerText = "5";
addNode.SetAttributeNode(addNodeName);
addNode.SetAttributeNode(addNodeUrl);
addNode.SetAttributeNode(addNodeSaveDays);
//将新建的子节点挂在到要加载的节点上
parentNode.AppendChild(addNode);
xmlDoc.Save(xmlFile);
}
示例12: CreateXml
/// <summary>
/// Creates the FetchXML Query.
/// </summary>
/// <param name="xml">The FetchXMLQuery.</param>
/// <param name="cookie">The paging cookie.</param>
/// <param name="page">The page number.</param>
/// <param name="count">The records per page count.</param>
/// <returns>Formatted FechXML Query</returns>
protected string CreateXml(string xml, string cookie, int page, int count)
{
StringReader stringReader = new StringReader(xml);
XmlTextReader reader = new XmlTextReader(stringReader);
// Load document
XmlDocument doc = new XmlDocument();
doc.Load(reader);
XmlAttributeCollection attrs = doc.DocumentElement.Attributes;
if (cookie != null)
{
XmlAttribute pagingAttr = doc.CreateAttribute("paging-cookie");
pagingAttr.Value = cookie;
attrs.Append(pagingAttr);
}
XmlAttribute pageAttr = doc.CreateAttribute("page");
pageAttr.Value = System.Convert.ToString(page);
attrs.Append(pageAttr);
XmlAttribute countAttr = doc.CreateAttribute("count");
countAttr.Value = System.Convert.ToString(count);
attrs.Append(countAttr);
StringBuilder sb = new StringBuilder(1024);
StringWriter stringWriter = new StringWriter(sb);
XmlTextWriter writer = new XmlTextWriter(stringWriter);
doc.WriteTo(writer);
writer.Close();
return sb.ToString();
}
示例13: StoreOauthAccessToken
/// <summary>
/// persist the Oauth access token in OauthAccessTokenStorage.xml file
/// </summary>
internal static void StoreOauthAccessToken(Controller page)
{
string path = page.Server.MapPath("/") + @"OauthAccessTokenStorage.xml";
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode node = doc.CreateElement("record");
XmlAttribute userMailIdAttribute = doc.CreateAttribute("usermailid");
userMailIdAttribute.Value = page.Session["FriendlyEmail"].ToString();
node.Attributes.Append(userMailIdAttribute);
XmlAttribute accessKeyAttribute = doc.CreateAttribute("encryptedaccesskey");
string secuirtyKey = ConfigurationManager.AppSettings["securityKey"];
accessKeyAttribute.Value = CryptographyHelper.EncryptData(page.Session["accessToken"].ToString(), secuirtyKey);
node.Attributes.Append(accessKeyAttribute);
XmlAttribute encryptedaccesskeysecretAttribute = doc.CreateAttribute("encryptedaccesskeysecret");
encryptedaccesskeysecretAttribute.Value = CryptographyHelper.EncryptData(page.Session["accessTokenSecret"].ToString(), secuirtyKey);
node.Attributes.Append(encryptedaccesskeysecretAttribute);
XmlAttribute realmIdAttribute = doc.CreateAttribute("realmid");
realmIdAttribute.Value = page.Session["realm"].ToString();
node.Attributes.Append(realmIdAttribute);
XmlAttribute dataSourceAttribute = doc.CreateAttribute("dataSource");
dataSourceAttribute.Value = page.Session["dataSource"].ToString();
node.Attributes.Append(dataSourceAttribute);
doc.DocumentElement.AppendChild(node);
doc.Save(path);
}
开发者ID:nberisha,项目名称:QuickbooksV3API-DotNet-Mvc3-Sample,代码行数:33,代码来源:OauthAccessTokenStorageHelper.cs
示例14: GetCapabilities
/// <summary>
/// Generates an XML containing WMTS capabilities.
/// </summary>
/// <param name="map">A MapAround.Mapping.Map instance</param>
/// <param name="serviceDescription"></param>
/// <returns>A System.Xml.XmlDocument instance containing WMTS capabilities in compliance to the WMS standard</returns>
public static XmlDocument GetCapabilities(Map map,
WmtsServiceDescription serviceDescription)
{
XmlDocument capabilities = new XmlDocument();
capabilities.InsertBefore(capabilities.CreateXmlDeclaration("1.0", "UTF-8", string.Empty),
capabilities.DocumentElement);
XmlNode rootNode = capabilities.CreateNode(XmlNodeType.Element, "WMTS_Capabilities", wmtsNamespaceURI);
rootNode.Attributes.Append(createAttribute("version", "1.0.0", capabilities));
XmlAttribute attr = capabilities.CreateAttribute("xmlns", "xsi", "http://www.w3.org/2000/xmlns/");
attr.InnerText = "http://www.w3.org/2001/XMLSchema-instance";
rootNode.Attributes.Append(attr);
rootNode.Attributes.Append(createAttribute("xmlns:xlink", xlinkNamespaceURI, capabilities));
XmlAttribute attr2 = capabilities.CreateAttribute("xsi", "schemaLocation",
"http://www.w3.org/2001/XMLSchema-instance");
rootNode.AppendChild(GenerateServiceNode(ref serviceDescription, capabilities));
rootNode.AppendChild(GenerateCapabilityNode(map, serviceDescription, capabilities));
capabilities.AppendChild(rootNode);
return capabilities;
}
示例15: GetPartInfoXMLRequest
public static string GetPartInfoXMLRequest(string cliinfo,string productid)
{
XmlDocument doc = new XmlDocument();
XmlElement root,node,node_1;
XmlDeclaration dec;
// doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.AppendChild(dec= doc.CreateXmlDeclaration("1.0", "", ""));
root= doc.CreateElement("REQ");
doc.AppendChild(root);
node= doc.CreateElement("CLIINFO");
node.InnerText = cliinfo;
root.AppendChild(node);
node = doc.CreateElement("FUNCTION");
node.InnerText="PT000V_PartInfo";
root.AppendChild(node);
node = doc.CreateElement("VERSION");
node.InnerText = "1.0.0.0";
root.AppendChild(node);
node=doc.CreateElement("ELE");
XmlAttribute attr=doc.CreateAttribute("NAME");
attr.Value="PARTINFO";
node.Attributes.Append(attr);
attr = doc.CreateAttribute("NAME");
attr.Value = "PARTINFO";
node_1=doc.CreateElement("ATTR");
node_1.Attributes.Append(attr);
node_1.InnerText=productid;
node.AppendChild(node_1);
root.AppendChild(node);
return doc.InnerXml;
}