Design implementation : Uploading XML file and evaluation of predefined path - c#

I have a .xml file, which is the result of an export from a non-relational database.
In my application, as a configuration, a user should be able to select nodes from a xml structure, which would be compared/evaluated later on when he upload the .xml.
I have thought to 2 options, but am not very pleased with both:
option1: the structure of the .xml file has to be stored in the database, so the application can display a TreeView, and the user would simply select the nodes to inspect.
(cons: I have many .xml files, one for each system it relates too and each .xml is quit large)
option2: the user would have to upload a .xml file before starting his configuration, so that its structure would be dynamically generated.
(cons: User has one more step to do in order to make his configuration. The one .xml file that he uploads may not contains all the nodes it could have)
Or maybe there are different ways than displaying a TreeView for that purpose ? As it is hard for me to think out of the box, I can't see other options.
I hope this is clear enough,
Maybe there is a kind of best practices I have missed, I am open to suggestions.

I would go with an intermediate option.
Generate dynamically the xsd schemes corresponding to your xml files and store them somewhere.
Process all the xml files in order to have the most complete xsd, because you said that each xml may not contain the whole structure.

Related

Recommended data format/structure for saving many tags belonging to files?

My goal is to efficiently and simply save tags belonging to image files in a directory. The tags should be stored inside a file that is created.
Let's say in the directory, there is a file 'duck.jpg'. Then p.e. I would like to assign tags 'animal' and 'bird' to this file. The tags are assigned with an image slider, where you tick off checkboxes, and then the tags should be associated with the files.
My question is what data structure / file format would be optimal for this problem. I thought about JSON, XML etc.
The resulting file should not be too big, as tags for many images will be stored, and it must be loadable quickly again and extendable (e.g. adding a new file to the structure should be possible).
What approach would be best suited for the problem?

How to convert Visio document .xml to csv file c#

I have multiple xml files, this files generated from convert .vsdx "Visio File" to .xml file, Now i want to convert the generated files from .xml to .csv files.
My problem the files has hundreds lines and the xml shape tag can't be followed to extract csv file using xml tag.
I work with this tool but the problem the out structure very complex
there is any way to make that ?
Normally one solves this with XSLT. If you want to create a csv file programmatically I would query the xml file with Linq to Xml append each record as a csv formatted line into a StringBuilder instance and finally write the StringBuilders content into the target file.
I haven't worked with Visio based XML files but given that the XML'ishness is alike across any source (which it should be), I'd go LINQ2XML or, depending on what you feel convenient with read in the stuff as a XDocument (avoid XmlDocument, as it's older and obsolete) and then parse it to a String.
It depends a bit on how complex files are and how invasive operations that you'll need to carry out.
As for the tool you mention, I haven't seen it before but it could be a better idea not to use it as it strikes me as a bit outdated. However, I only glanced at it without scrutinizing. If you only need to see the data for yourself (human based analysis of the contents), you might perhaps use a decent text editor with some appropriate plugin (such as Notepad++ and its XML add-on).

Maintaining multiple settings files

Currently, I have a form that has various radio buttons, directory browsers, date pickers etc. The application uses the settings, and executes a file deletion task. I was wondering what is the best strategy to save these settings to an external file that can be loaded at a later date. So essentially each configuration can be loaded, executed, and then another configuration loaded. Also, the configuration can be passed across installations / users.
I dont believe I can use the internal .settings file because I will have multiple sets of settings that can be loaded.
There are many formats to choose from for storing settings such as:
INI
CSV
YAML
JSON
XML
One of the best strategies would be to use XML. XML is one of the most popular formats for setting/configuration files because its easy to parse, the syntax is well specified and is powerful yet easy to read.
Using XML files allows configurations to be passed across installations and shared among users.
In addition if you have an XSD (schema file) that describes your XML configuration files, it is trivial for your application to validate different configuration files.

what is actually xsd file,is it a schema file or dataset file?

i know XSD is xml schema definition language file used for validating XML just like DTD was doing, but now i really doubt is it a xml file or dataset file?. The reason behind it is , i have c# project contains timberdata.xsd ,but when i opened that i could see a lot of data table that means thats dataset file??. But actually xsd what i know is a schema file for validating xml
when i checked our database mydata.xml i could see an entry of shown below
<?xml version="1.0" standalone="yes"?>
<timberdataSchema xmlns="http://tempuri.org/timberdata.xsd">
So does this xml file is schema file i mean xsd file or the one which i can see in our project "timberdata.xsd" contains lot of datatable so dataset.
One more question is when i checked properties of timberdata.xsd i can see Customtool entry is filled with "MSDataSetGenerator" what does this means?
i can see along with "timberdata.xsd" timberdata.xsc and timberdata.xss both are in xml format which is xsd file??
XSD is always an XML file (XML is format, it does not define anything about what data is).
XSD can easily define parent-child relationship and basic type restrictions needed to define tables - so can be used as database schema. "MSDataSetGenerator" is the "custom tool" that builds whatever files/binaries are needed from the XSD whenever XSD is saved.
Here is explanation of custom tools - Single-File Generators and how MSDataSetGenerator is registered in Registering Single File Generators.
XSD can also define strange and complicated things if you want too...
I think you are asking about file extensions. Windows and Unix, being fairly ancient operating systems, do not have any reliable type information associated with files, so they try to guess what is in a file from the last part of the file name (and/or the first few bytes of the file!). But file extensions are a matter of convention only; there is no standard registry of file extensions, and there is nothing to stop anyone creating a file with extension .xml that doesn't contain XML, for example. So a file with extension .xsd could contain anything at all.
In fact operating systems generally allow the user or system administrator to set up an association between file extensions and particular programs, so you might for example associate the .xsd extension with an XML Schema processor. But someone else might associate the same extension with a "dataset file processor" (whatever that is), and neither would be right or wrong.

RESX files and xml data

What is the best way to store XML data used in a program ? Use RESX file or store it as a .xml file and load and unload the files as per requirement
A third option would be to put the XML file as embedded resource in the assembly. In that case, use Assembly.GetManifestResourceStream() to load the XML.
As Cerebrus wrote, when localization is necessary, RESX would be the way to go.
.resx files are XML files albeit conforming to a particular schema (Microsoft ResX Schema v2.0). This schema was designed with the explicit aim of being easily human readable and editable manually.
I see no problem with storing your data as XML files. Basically it depends on the function of the data - If it is localizable resources that you are trying to store, go with the established .resx files. If not, you are free to use your XML with custom schema.
Putting XML (blobs) in .resx
Positives:
Readily available
Negatives:
It would increase the memory load, if the content is big in size. Big-in-size is in comparison to assembly size without content. If an assembly size is 10kb and content size is 10kb, even though 10kb is not bigger in today's scenario, one can reduce assembly size to half just by keeping content in separate file.
Code manageability goes to down drastically, by keeping XML as string Key-value-pairs in
RESX. As resx editor is not be XML sensitive.
If one is very keen keeping xml content as embedded resource, you can create XML file and keep it as file resource inside RESX.

Categories

Resources