简体   繁体   English

如何使用WriteStartElement重命名xmlns =“”?

[英]How do I rename xmlns=“” with WriteStartElement?

I'm attempting to make an XML that's going to be parsed by an XNA content reader. 我正在尝试制作一个将由XNA内容阅读器解析的XML。 I'm using XMLWriter, and the format is supposed to be: 我正在使用XMLWriter,格式应该是:

<XNAContent>
     <Assest Type="namespace">
          <Element>"Value"</Element>
     </Asset>
<XNAContent>

But when I use WriteStartElement to declare a namespace, I get: 但是当我使用WriteStartElement来声明命名空间时,我得到:

 <XNAContent>
     <Assest xmlns="namespace">
          <Element>"Value"</Element>
     </Asset>
<XNAContent>

It's important that I have Asset Type= instead of Asset xmlns= because of what the pipeline expects, but I can't find an overload that let's me rename that default tag. 重要的是,由于管道的期望,我使用Asset Type=而不是Asset xmlns= ,但是我找不到重载,因此让我重命名该默认标记。

Is there a way for XMLWriter to let me put my own tag there as described? XMLWriter有没有办法让我按照说明放置自己的标签? Thanks, all. 谢谢,所有。

You are confusing XML attributes with namespaces, xmlns is a 'special' attribute that defines the namespace for an XML element and its children. 您将XML属性与名称空间混淆, xmlns是一个“特殊”属性,用于定义XML元素及其子元素的名称空间。 Whereas your Type is simple an attribute. 而你的Type是一个简单的属性。 To write an attribute value use the WriteAttributeString method. 要写入属性值,请使用WriteAttributeString方法。

For example: 例如:

 writer.WriteStartElement("Asset");

 writer.WriteAttributeString("Type", "namespace");

 writer.WriteEndElement();

will result in 会导致

<Asset Type="namespace">
</Asset>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用C#将`xmlns`重命名为TYPE - How to rename `xmlns` as TYPE using C# 如何使用XMLWriter更改C#中新的StartElement中的xmlns? - How do I change the xmlns in a new StartElement in C# with XMLWriter? 如何摆脱子元素中的空名称空间“ xmlns =”“”? - How do I get rid of empty namespaces “xmlns=”“” in subelements? 如何摆脱XmlSerializer插入的xmlns声明? - How do I get rid of the xmlns declarations inserted by the XmlSerializer? 如何删除添加到新创建的XElement节点的xmlns =“”属性? - How do I remove the xmlns=“” attribute added to newly created XElement nodes? 如何重命名 Blazor WASM 项目? - How do I rename a Blazor WASM project? WCF RESTful服务-如何使我的服务在请求中不需要xmlns属性? - WCF RESTful service - How do I make my service not need the xmlns attribute in a request? 我如何绑定到XmlDataProvider,谁的源设置了默认名称空间(xmlns)? - How do I bind to XmlDataProvider whos source has a default namespace (xmlns) set? 如何在 .net 内核的返回 xml 中删除 xmlns:xsi 和 xmlns:xsd? - How can I remove xmlns:xsi and xmlns:xsd in the return xml in .net core? 如何重命名特定XML元素的所有出现? - How do I rename all the occurrences of a particular XML element?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM