XML WriteAttributeString 错误 [英] XML WriteAttributeString error

查看:24
本文介绍了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'相同的开始元素标签.

The prefix '' cannot be redefined from '' to 'urn:nsSBAK' within the same start element tag.

你能帮我吗?

推荐答案

您需要在 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 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆