读书人

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

发布时间: 2012-03-21 13:33:15 作者: rapoo

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

读书人网 >C#

热点推荐