我正在通过 C# 代码动态构建 xml,但出现此错误
“指定节点不能作为该节点的有效子节点插入,因为指定节点是错误的”
这是我的主课
internal class Program
{
private static void Main(string[] args)
{
CreateXml xml = new CreateXml();
xml.multipleXML();
}
}
Run Code Online (Sandbox Code Playgroud)
我在下面评论为“错误”,其中出现运行时异常。请帮助如何修复此错误。
我的 Xml 课程在这里。
internal class CreateXml
{
private XmlDocument HandlingXmlDoc;
private String baseHandlingXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?><SHandling><BLocation><SLocation><Identifier>02898</Identifier></SLocation></BLocation><Context><UserName>0289800001</UserName><Application>STOCK</Application></Context><Counting><SubmissionDateTime>2014-04-02T16:38:48.9345238+01:00</SubmissionDateTime><ProcessImmediately>YES</ProcessImmediately><Counts><Count><ProductIdentifier>050025488</ProductIdentifier><CountDateTime>2014-04-02T16:38:49.366567+01:00</CountDateTime><LocationCounts></LocationCounts></Count></Counts></Counting></SHandling>";
private XmlDocument locCountXmlDocument;
private String baseLocCountXML = "<LocationCount><Name>Bangalore</Name><SCounts><SCount><Quantity>1</Quantity><UnitOfMeasure>CASES</UnitOfMeasure></SCount><SCount><Quantity>1</Quantity><UnitOfMeasure>SINGLES</UnitOfMeasure></SCount></SCounts></LocationCount>";
public CreateXml()
{
Initialise();
}
public String GetStockHandlingXmlString { get { return HandlingXmlDoc.OuterXml; } }
public XmlDocument GetStockHandlingXmlDocument { get { return HandlingXmlDoc; } }
private void Initialise()
{
HandlingXmlDoc …
Run Code Online (Sandbox Code Playgroud) 我有一个 json 数据作为输入字符串。现在我需要用输入的 Json 数据更新现有的 Json 数据。就我而言,我想遍历每个键并与现有 Json 数据进行匹配,然后使用输入 Json 数据更新该键的值。
检索现有数据的代码
var existingJSon = ProductRepository.ListOfProd.Cast<JArray>().Where(x => x["ProdId"].ToString() == id.ToString());
Run Code Online (Sandbox Code Playgroud)
检索数据后,我现有的 Json 将如下所示。
{
ProdId:"1",
Title:"C#",
Author:"Jeffy",
Publisher:"XYZ",
Category:"Microsoft"
}
Run Code Online (Sandbox Code Playgroud)
现在我需要循环遍历作为输入的每个键并与现有的 Json 键匹配并更新该键的值。
输入并更新后应如下所示:
{
ProdId:"1",
Title:"C#",
Author:"Jeffy",
Publisher:"abcd",
Category:"Microsfot Basic .Net Development Kit"
}
Run Code Online (Sandbox Code Playgroud) 我开始通过下载 Swashbuckle 来运行项目“Swashbuckle.Dummy.SelfHost”。然后我转到浏览器并检查在program.cs类的主函数中声明的URL。当我在浏览器中给出相同的URL(例如“http:/ localhost:8090/swagger”)时,我收到以下错误。任何人都可以指导我逐步运行旋转扣解决方案并进行测试吗?如果我想在 IIS 上托管此应用程序并运行,我需要遵循哪些步骤?
An error has occurred.
Could not load file or assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
System.IO.FileLoadException
at Swashbuckle.Application.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.HttpServer.<>n__FabricatedMethod9(HttpRequestMessage , CancellationToken ) at System.Web.Http.HttpServer.d__0.MoveNext()
Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我将多个字典实例捆绑到一个列表中.现在我想从列表中仅选择不同的值.要做到这一点,我尝试使用distinct和group by但从未帮助过我.任何人都可以帮我选择使用linq的独特方式吗?
IList<Dictionary<string, string>> lst = new List<Dictionary<string, string>>();
Dictionary<string, string> d = new Dictionary<string, string>();
Dictionary<string, string> d1 = new Dictionary<string, string>();
Dictionary<string, string> d3 = new Dictionary<string, string>();
d.Add("12345", "xyz");
d1.Add("12345", "xyz");
d3.Add("123456", "xyz-abc");
lst.Add(d);
lst.Add(d1);
lst.Add(d3);
var result = lst.Distinct(); //test => test.Values.ToString().Trim()); //.Select(grp => grp.First());
Run Code Online (Sandbox Code Playgroud)