首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

创建xml的有关问题,哪位高手会啊 哪位高手会

2012-03-21 
创建xml的问题,谁会啊~~ 谁会C# code XmlDocument doc new XmlDocument() XmlElement root doc.Creat

创建xml的问题,谁会啊~~ 谁会

C# code
 XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("offers"); doc.AppendChild(root); XmlAttribute xsi = doc.CreateAttribute("xmlns:xsi"); xsi.Value = "http://www.w3.org/2001/XMLSchema-instance"; XmlAttribute xsispace = doc.CreateAttribute("xsi:noNamespaceSchemaLocation"); xsispace.Value = "feed.xsd"; root.Attributes.Append(xsi); root.Attributes.Append(xsispace);

我这样写,生成出来的是这样的
<offers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="feed.xsd">

但要求是这样的
<offers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="feed.xsd">


后面的那个xsi:不知道咋弄不出来

[解决办法]
改改就行了:

XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("offers");
doc.AppendChild(root);
XmlAttribute xsi = doc.CreateAttribute("xmlns:xsi");
xsi.Value = "http://www.w3.org/2001/XMLSchema-instance";
XmlAttribute xsispace = doc.CreateAttribute("xsi", "noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
xsispace.Value = "feed.xsd";
root.Attributes.Append(xsi);
root.Attributes.Append(xsispace);

热点排行