c#xmlwriter创建特定的行格式 [英] c# xmlwriter create a specific line format

查看:65
本文介绍了c#xmlwriter创建特定的行格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在使用xmlwriter遇到路障,因为我正在编写一个xml文件,该文件必须符合特定行的特定标准有一种格式我似乎无法使用 .WriteStartElement() .WriteAttributeString()正确输出。



我确定这是我的脑力,但这是我需要输出的等效线。



Hello,

I am running into a road block with xmlwriter in that I am writing an xml file that has to conform to a certain standard for a specific line has a format I can not seem to output correctly using .WriteStartElement() and .WriteAttributeString().

I sure it is a brainfart on my part, but here is the equivalent line I need to output.

<toc:file toc:URI="file:///filename.ice" />







我得到我需要 .WriteStartElement(toc,file,Insert something); 来获取第一部分。

第二部分,我无法弄清楚如何在之前获得toc: URI =file //...\" part。



有关我在这里缺少什么的想法吗?



谢谢。




I get that I need .WriteStartElement("toc","file","Insert something"); to get the first part.
The second part, I can not figure out how to get the "toc:" before the "URI="file//..." part.

Any thoughts on what I am missing here?

Thanks.

推荐答案

toc:前缀将与XML命名空间URI - 插入内容部分 WriteStartElement 调用。您需要将相同的URI传递给 WriteAttributeString 方法:

The toc: prefix will be associated with an XML namespace URI - the "Insert something" part of your WriteStartElement call. You need to pass the same URI to the WriteAttributeString method:
const string TocNamespaceUri = "...";

writer.WriteStartElement("toc", "file", TocNamespaceUri);
writer.WriteAttributeString("URI", TocNamespaceUri, "file:///filename.ice");
writer.WriteEndElement();



这将为您提供一个如下节点:


This will give you a node which looks like:

<toc:file toc:URI="file:///filename.ice" xmlns:toc="..." />



名称空间URI需要是特定值 - 您需要检查规范提出要查明的内容。


The namespace URI will need to be a specific value - you'll need to check the specification for the file to find out what that is.


这篇关于c#xmlwriter创建特定的行格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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