In my project, there are multiple xml files. Main xml files contains references of other xml files and so on using Attribute.
Sample XML
A.XML
<AList>
<A Id="1"><Name>A</Name></A>......
</AList>
Id = 1 means read data from B.xml contaijg Id = 1.
B.xml
<BList>
<B Id="1"><Name>A</Name></B>......
</BList>
There are around 20 XMl files and these are very complex files. I want to search each and every xml file to find out proper values.
Approach 1
Using XDocument, I am loading all these xml and then using XDoucment I am reading values using Descendent property and sending data back to service.
Approach 2
Write domain model, class containing get and set properties prepared for this. In case of domain model, I have to serialize each and every XML, then using for loop, I have search for right data. Then I have to send this data back to some service.
Which approach is better ?
If all your application does is searching data in xml and sending that xml to some service, then there is no need for domain model.
If you have complex business rules, and much more logic, than simply sending xml you have found, then consider to create domain model. In that case you don't need to serialize domain classes into xml to perform search - search will occur on domain entities level (e.g. with some domain service).
Related
I'm working on a solution that posts data to a SOAP web service. My sending application has a database table that holds the mappings between that application and the receiving application.
I've generated a class from the XSD using xsd tools. Ideally the solution will then traverse the elements within the xsd/class and if the element name sits in my database table, it will set that elements property accordingly.
First I found this documentation from Microsoft
https://learn.microsoft.com/en-us/dotnet/standard/data/xml/traversing-xml-schemas
But it only finds one level of parent and child
Then I kept digging and found this post on here
Traversing XML Schemas failed
This gives me the same result, so I can only assume its the schema that is the problem?
This is what is looks like, I can't get to "Type" for example
Schema
I have a dashboard with many tables that I need to be able to export to excel. Each table is based on a domain model object collection from my domain model.
I have written some code that will take the collection and create an excel file from the data it contains.
Where does this code go? As a first pass, I just stuck it in my controller method. Once I create the excel file I return that in the controller. Easy, but clearly that's no good. But I can't imagine this goes in my domain either.
Where should this code go? I can't seem to classify it as controller logic, domain logic, or anything else. I'm basically serializing a domain object into data in an excel file and returning that to the client.
Eventually what I would like to do is have this code grab the data as json from a url and serialize that into an excel file. Again, I have no idea where that code should go either.
The project I'm working on is an Extranet. I need to call a webservice in this project that communicates with the database. This works as an APPserver.
The procedures between the APPserver and the database are written in Progress. The output that I receive from the webservice is an object that contains XML.
Is it possible to convert the XML file to objects? For example, I have a node
<user>
<uid></uid>
<lastname></lastname>
<firstname></firstname>
</user>
Can this user node convert to a User entity?
The complexity is much higher when it starts with relationships. How the XML will look like, I can't really say at this time.
Are there any other possible frameworks / languages I could use, so they simplify this process?
What will happen with the structure of the relationships and how to handle them?
This example is from an old version of .NET, but it is still relevant. Use XML deserialization to load objects based on an XML format. You can have nested classes. Just decorate all classes/properties as necessary to create the proper format when the object is serialized, and you'll be able to deserialize XML into objects back at the webservice.
http://www.codeproject.com/Articles/4491/Load-and-save-objects-to-XML-using-serialization
I want to use the powerful DataContractSerializer to write or read data to the XML file.
But as my concept, DataContractSerializer can only read or write data with entire structure or list of structure.
My use case is describe below....I cannot figure out how to optimize the performance by using this API.
I have a structure named "Information" and have a List<Information> with unexpectable number of elements in this list.
User may update or add new element into this list very often.
Per operation (Add or Update), I must serialize all the element in the list to the same XML file.
So, I will write the same data even they are not modified into XML again. It does not make sense but I cannot find any approach to avoid this happened.
Due to the tombstoning mechanism, I must save all the information in 10 secs.
I'm afraid of the performance and maybe make UI lag...
Could I use any workaround to partially update or add a data information into the XML file by DataContractSerializer?
DataContractSerializer can be used to serialize selected items - what you need to do is to come up with scheme to identify changed data and way to efficiently serialize it. For example, one of the way could be
You start by serializing entire list of structures to an file.
Whenever some object is added/updated/removed from list, you create a diff object that will identify kind of change and the object changed. Then you can serialize this object to xml and append the xml to file.
While reading the file, you may have to apply similar logic, first read list and then start applying diffs one after another.
Because you want to continuous append to file, you shouldn't have root element in your file. In other words, the file with diff info will not be an valid xml document. It would contain series of xml fragments. To read it, you have to enclose these fragments in a xml declaration and root element.
You may use some background task to write the entire list periodically to generate valid xml file. At this point, you may discard your diff file. Idea is to mimic transactional system - one data structure to have serialized/saved info and then another structure containing changes (akin to transaction log).
If performance is a concern then using something other than DataContractSerializer.
There is a good comparison of the options at
http://blogs.claritycon.com/kevinmarshall/2010/11/03/wp7-serialization-comparison/
If the size of the list is a concern, you could try breaking it into smaller lists. THe most appropriate way to do this will depend on the data in your list and typical usage/edit/addition patterns.
Depending on the frequency with which the data is changed you could try saving it whenever it is changed. This would remove the need to save it in the time available for deactivation.
Possible Duplicate:
Programmatically Create XML File From XSD
XML instance generation from XML schema (xsd)
How to generate sample XML documents from their DTD or XSD?
Here's the scenario: I've created an application that hooks into a commercial CRM product using their web service API, which unfortunately has a different schema for every installation, based on how the users create their custom fields. This schema can also be modified at any time. This application will be installed at the customer location, and will need to function even when they change their field structure.
In order to insert or update a record, I first call their Project.GetSchema() method, which returns the XSD file based on the current set of fields, and then I can call the Project.AddProject() method, passing in an XML file containing the project data.
My question is: What's the best way to generate the XML from the XSD file at runtime? I need to be able to check for the existence of fields, and fill them out only if they exist (for instance, if the customer deleted or renamed some fields).
I really don't want to have the application attempting to recompile classes on the fly using xsd.exe. There simply must be a better way.
[update] My current solution, that I'm working on, is to basically parse out the XSD file myself, since the majority of the schema is going to be the same for each installation. It's just an ugly solution, and I was hoping there was a better way. The biggest problem I have is that their schema uses xsd:sequence, so putting things in a different order always breaks validation.