c# - 将带有命名空间的 XML 转换为 C# 模型类
问题描述
有人可以帮我解决以下问题。我想使用 C# 模型类创建一个具有命名空间和属性的 xml
目前,我创建了一个这样的字符串:
var xmlFile =
@"<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>
<s:Body>
<GetAllowedCategoryTree xmlns='http://www.cdiscount.com'>
<headerMessage xmlns:a='http://schemas.datacontract.org/2004/07/Cdiscount.Framework.Core.Communication.Messages' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<a:Context>
<a:SiteID>100</a:SiteID>
</a:Context>
<a:Localization>
<a:Country>Fr</a:Country>
<a:Currency>Eur</a:Currency>
<a:DecimalPosition>2</a:DecimalPosition>
<a:Language>Fr</a:Language>
</a:Localization>
<a:Security>
<a:DomainRightsList i:nil='true' />
<a:IssuerID i:nil='true' />
<a:SessionID i:nil='true' />
<a:SubjectLocality i:nil='true' />
<a:TokenId>" + token + @"</a:TokenId>
<a:UserName i:nil='true' />
</a:Security>
<a:Version>1.0</a:Version>
</headerMessage>
</GetAllowedCategoryTree>
</s:Body>
</s:Envelope>";
但我想使用对象,因为它更容易。
唯一变化的字段是tokenId
,这也是我要设置的字段。
我不知道如何制作一个具有类似 xml 元素的类<s:Envelope xmlns:s='...'>
非常感谢您的关注!
解决方案
推荐阅读
- c# - 找不到类型或命名空间名称 Excel
- c# - 双异常不一致(System.IO.FileNotFoundException / System.Runtime 程序集版本)
- javascript - Javascript如何在字符串中找到字符“utf-16”
- javascript - 重新分配类的功能时奇怪的Javascript行为
- angular - Angular 6 Reactive forms - 触发焦点/模糊验证
- r - 将json转换为数据框
- javascript - 比较两个对象数组并将具有匹配值的对象添加到第一个对象数组
- javascript - Vue.js - 应该使用哪个组件生命周期来获取数据?
- java - 使用 PDFBox 创建外部链接
- composer-php - Composer - 如何包含测试用例