关于XML创建。 [英] Regarding XML Creation.
本文介绍了关于XML创建。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello All
我无法执行下面显示的简单代码
请帮助同样
Hello All
I was un able to execute a simple code shown below
Please help on the same
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>");
//Create an attribute.
XmlAttribute attr = doc.CreateAttribute("publisher#");
attr.Value = "WorldWide Publishing";
//Add the new node to the document.
doc.DocumentElement.SetAttributeNode(attr);
Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out);
}
}
推荐答案
行,
XmlAttribute attr = doc。 CreateAttribute(发行商#);
导致问题。
特殊字符''#' '对属性名称无效。
The line,
XmlAttribute attr = doc.CreateAttribute("publisher#");
causes the issue.
Special character ''#'' is not valid for attribute name.
这篇关于关于XML创建。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文