C# 将XML数据嵌套到集合子级

C# 将XML数据嵌套到集合子级,c#,xml,json,C#,Xml,Json,我正在用C#编码。我有一个需要转换为JSON对象的XMLDocument对象(我目前正在使用Newtonsoft)。XML看起来像 <Form attribute1="value1"> <BusinessName>BusinessName</BusinessName> <AccountName>Account</AccountName> </Form> 但实际上,我需要在JSON集合中包含XML数据。看起来是这样的: "@

我正在用C#编码。我有一个需要转换为JSON对象的XMLDocument对象(我目前正在使用Newtonsoft)。XML看起来像

<Form attribute1="value1">
<BusinessName>BusinessName</BusinessName>
<AccountName>Account</AccountName>
</Form>
但实际上,我需要在JSON集合中包含XML数据。看起来是这样的:

"@attribute1" : "value1",
"CollectionFieldName" : {
  "BusinessName" : "Business",
  "AccountName" : "AccountName"
}
集合中只有一个项目。最好修改XMLDocument,然后执行一个简单的JsonConvert.SerializeXmlNode。或者我应该转换原始的XMLDocument,然后操作生成的JSON字符串>

当前代码类似于:

XmlDocument serializedFormXML = new XmlDocument();
serializedFormXML.LoadXml(serializedForm); 
string s = JsonConvert.SerializeXmlNode(serializedFormXML, Formatting.None, true);

任何帮助都将不胜感激

如果你能提供一个简短但完整的例子来说明这个问题,这将非常有帮助。(我个人建议使用linqtoxml-XDocument和friends-而不是XmlDocument。)我更新了这个问题,不知道如何将json、XML和c#格式化为代码片段。我将它们全部缩进了四个空格。@user1562497这两种方法都可以,但是如果您可以控制XML结构,为什么不首先简单地更改XML呢?顺便说一句,您的格式设置很接近,每个代码块只漏了一行换行符。谢谢,我无法控制原始xml结构,我正在读取xml文档中的规范化数据。因此,操作xml将全部存储在内存中。描述一下我将如何实现这两种解决方案都将是非常棒的。
XmlDocument serializedFormXML = new XmlDocument();
serializedFormXML.LoadXml(serializedForm); 
string s = JsonConvert.SerializeXmlNode(serializedFormXML, Formatting.None, true);