使用XML文本在C#中? [英] Use XML Literals in C#?

查看:85
本文介绍了使用XML文本在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能一个C#代码文件中添加文字XML数据?我目前使用的是多行字符串,但它变得混乱,你可以看到。 ?该做的。



 字符串的XML没有更好的办法= @< XML版本=1.0,编码= UTF-8> 
< customUI的xmlns =http://schemas.example.com/customui>
<工具栏ID =保存,> ;
< /工具栏>
< / customUI>中;


解决方案

XML文字是VB.NET的功能,而不是C#。



您有哪些发布是接近你可以在C#中获得。



您可能要考虑用单引号代替嵌入式双引号虽然(因为这两种类型都有效的XML)。



有关更大量的XML,你可能要考虑从马克的答案 - 使用XML文件(加载一次,并存储在内存中),这样就可以充分利用XML编辑器的


Is it possible to add literal XML data within a C# code file? I'm currently using a multiline string literal but it gets messy as you can see. Any better way of doing this?

string XML = @"<?xml version=""1.0"" encoding=""utf-8""?>
<customUI xmlns=""http://schemas.example.com/customui"">
    <toolbar id=""save"">
    </toolbar>
</customUI>";

解决方案

XML literals are a feature of VB.NET, not C#.

What you have posted is as close as you can get in C#.

You may want to consider replacing the embedded double quotes with single quotes though (as both types are valid XML).

For larger amounts of XML you may want to consider the answer from Marc - using an XML file (loaded once and stored in memory), so you can take advantage of the XML editor.

这篇关于使用XML文本在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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