本文介绍了XML WriteAttributeString 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在这里写这篇文章时:

When I write this entry here:

<XmlRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nsSBAK" xsi:schemaLocation ="urn:nsSBAK SBAK.xsd">

使用此代码:

xmlWriter.WriteStartElement("XmlRoot");
xmlWriter.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
xmlWriter.WriteAttributeString("xmlns", null, null, "urn:nsSBAK");
xmlWriter.WriteAttributeString("schemaLocation", null, "urn:nsSBAK SBAK.xsd");

我收到调试错误:

前缀 '' 不能重新定义从 '' 到 'urn:nsSBAK'相同的开始元素标签.

你能帮我吗?

推荐答案

您需要在 WriteStartElement 本身上定义元素的命名空间.还注意到您没有将命名空间添加到您的 schemaLocation.至您想要的结果.在我的示例中还为您添加了:

You need to define the namespace of the element on the WriteStartElement itself.Also noticed you did not add the namespace to your schemaLocation. wich you dit in your desired result. Also added that for you in my example:

xmlWriter.WriteStartElement("XmlRoot", "urn:nsSBAK");
xmlWriter.WriteAttributeString("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "urn:nsSBAK SBAK.xsd");

这篇关于XML WriteAttributeString 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 23:33