日期:2014-05-18  浏览次数:20772 次

创建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);