有没有一种方法可以在 C# 代码中定义多行 XML,而无需更改“”到“”?

发布于 2024-08-17 21:22:10 字数 479 浏览 4 评论 0原文

我希望能够将 XML 块粘贴到我的 C# 代码中。

但是,我能做的最好的就是以下,但随后我必须搜索“替换为””。

有吗有没有一种方法可以在 C# 代码中定义多行 XML,而无需像这样更改 XML 文本?

        public static string GetXml1()
        {
            return @"
<Customer>
  <FirstName status=""required"">Jim</FirstName>
  <LastName status=""required"">Smith</LastName>
</Customer>
";
        }

I would like to be able to paste chunks of XML into my C# code.

However, the best I can do is the following, but then I have to search and replace " with "".

Is there a way to define multiline XML in C# code without having to alter the XML text like this?

        public static string GetXml1()
        {
            return @"
<Customer>
  <FirstName status=""required"">Jim</FirstName>
  <LastName status=""required"">Smith</LastName>
</Customer>
";
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遇见了你 2024-08-24 21:22:10

将 XML 存储为字符串资源,然后使用 ResourceManager 检索 XML。

Store the XML as a string resource then retrieve the XML as using ResourceManager.

[浮城] 2024-08-24 21:22:10

不一定是您所要求的,但如果行对齐,“框/列选择”可能会有所帮助。只需按住“Alt”键,同时使用鼠标选择要删除的“,然后按删除即可。

Not necessarily what you are askin for, but Box/Column Select might help if the lines are alligned. Just hold down the 'Alt'-key while you use the mouse to select the " you want to remove and press delete.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文