自定义配置部分和app.config
我有一些传入的 XML 文档,我需要检查此传入 XML 中可配置的属性,如果正在检查的 XML 文档中不存在该属性,则添加它。
要检查的属性将在app.config文件中指定 OrderRequest.orderDetails.orderSummary.testCount,我需要检查元素OrderRequest下是否存在testCount属性。如果否,请将其与其值一起添加,该值也在 app.config
INCOMING XML 中指定 ->从 app.config 中读取需要在此 XML 文件中检查的属性 -->使用 XDocument 读取传入的 XML -->如果传入 XML 中不存在该属性,请将其添加到 XML 中。
有什么想法我可以继续做下去吗?
I have some incoming XML documents, I need to check attributes that are configurable in this coming XML and if the attribute is not there in the XML document being checked add it.
The attributes to be checked will be specified in the app.config file
OrderRequest.orderDetails.orderSummary.testCount, I need to check if the testCount attribute exists under the element OrderRequest. If No add it along with it’s value which is also specified in the app.config
INCOMING XML --> Read the attributes from the app.config which need to be checked in this XML file --> Read the incoming XML using XDocument --> If the attribute is not there in the incomg XML add it to the XML.
Any ideas how I can go on this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我写了一系列关于如何创建自定义配置部分的文章,可以在这里找到:http:// /dotnetslackers.com/articles/CustomConfiguration/default.aspx
这是静态开发任务吗?我的意思是,您是否只测试 testCount 属性,或者这是通用的循环遍历元素类型并检查其所有属性以确保它们存在的方法?
无论哪种方式,本质上您都必须找到一个元素,获取其名称,访问自定义配置部分并查找名称,使用 GetAttribute 方法检查属性是否存在,如果不存在,则将新属性附加到元素。
HTH。
I wrote a series of articles on how to create custom configuration sections, which can be found here: http://dotnetslackers.com/articles/CustomConfiguration/default.aspx
Is this a static development task? What I mean is, are you only testing the testCount attribute, or is this generic to say loop through the element type and check all of its attributes to ensure they are there?
Either way, essentially you have to find an element, get its name, access your custom configuration section and lookup the name, use the GetAttribute method to check for attribute existence, and append a new attribute to the element if not.
HTH.