Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi
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 eg.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.
Posted
Comments
Arindam Tewary 11-Jul-11 7:11am    
There are pleanty of API's available in .NET to do all sort of comparision, xml manupulation using .NET. What is your problem? Didnt you find the API's for xml processing?
ShonaR 11-Jul-11 8:05am    
Not aware of any such API.

I am not sure how the keys should be defined in the app.config so that they correspond to XML structure, was planning to use Custom configuration but it appears for that we should know in advance the structure but in this case the this is configurable can be changed everytime before the application is run.

I have a very big XML (incoming XML) thay want to add some new attributes (if not existing) to it under different elements, and these can change so have to define in app.config.

1 solution

Use LINQ to XML[^] for reading and checking the XML file, and if needed added or change values.

See simple examples on Querying XML Trees[^] and Adding Elements, Attributes, and Nodes to an XML Tree[^]
 
Share this answer
 
Comments
ShonaR 12-Jul-11 11:24am    
Thanks, I used XDocument.
Kim Togo 13-Jul-11 3:45am    
Great. Then the task is easier .-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900