Binary Decoder with xml specified data structure - c#

I want to build C# binary decoder. I have XML file which is describing data structure of binary file.
Next step is dynamically making data structures (in code) based on that XML.
Do you guys/girls have any comments, links, code, etc for me?
I am aware that this is general question, but I just want to start some where and I don't have clue from where.
EDIT:
Sorry need to remove code...
BR

Since you want to dynamically create the structures (rather than statically build classes based upon the XML definition), I guess you need a generic data structure which you can then query. What this looks like exactly would depend on what kind of data structures you're describing. Is it records and fields? Are there multiple record types in a hierarchy? If there's no hierarchy, you could just use a dictionary of key-value pairs for each field. If there is hierarchy, I'd have thought a navigable tree would cover most scenarios. You could use an XML DOM for this, but I think that's not the cleanest solution and I prefer to use generic tree structures. There isn't a built in one (see Tree data structure in C#), but it's fairly easy to create one with generics.
EDIT
The above assumes you want to dynamically create a structure to be used dynamically.
If you want to dymanically create a structure in code that will be used statically (e.g. you want to be able to write something like myDataStrucureThatWasDefinedInXml.MyProperty1), have a look at CodeDom.
And having thought some more about it, it really depends on what you want to do once you've deserialized your binary data. You might also want to look at the Expando object and Expression Trees.

To read and write content of XML document you can use XmlDocument class provided in C#.
Here are some links, which can help you:
http://www.codeproject.com/Articles/318876/Using-the-XmlReader-class-with-Csharp
http://www.codeproject.com/Articles/21167/XML-C-STARTING-GUIDE-First-Part

Related

long to xml, xsd.exe, custom classes

I have 3 classes that map to my database. I need to insert an xml file into the database via these classes. The xml and classes are structured differently. Should I use xsd.exe to generate the classes of the xml and then map these generated classes to my database classes? Or should I use linq to xml to directly map the xml to the classes.
My experiences with XSD were that if it works for what you are using it for, its a very convenient thing, and completely worth doing.
On the other hand though, Depending on how familiar you are with using linq, you will probably end up with a better overall solution if you write the conversion directly.
XSD can be very convenient but I'm not always a fan of how the results are spat out. Overall Personally I'd lean towards using linq.

Xml binary search through attributes

I have an xml document which contains tags with numerical attribute. They are sorted by this attribute. is it worth to finding this tags through binary search? Or access to the nodes are not in constant time and it is better to get the data to array? And is it implemented in xml libraries?
It depends how are you planing to read the document. There are two ways to handle XML documents:
First one, implemented by XmlReader, is stream-oriented and processes one element at a time, and nothing more is stored in program memory.
Second one follows Document Object Model interface: it loads the entire document into memory and allows you to query it without looking back to the file. The best method to use that in .NET is LINQ to XML.
Depending of the size of your document, it may be better to choose one or another, but you have to be aware that making any other then linear search with Stream-oriented API is not possible.
And as far I know there you can't get binary search with LINQ to XML out of the box, because it uses IEnumerable. You'd have to get an array of your elements and then implement the binary search on an array. Definitely not difficult task to complete anyway.

Need WPF XML Binding Advice

I have a C# WPF program that needs to display GridView and 2D graph data which initially will come from a hardware device. I also want to continuously (or frequently periodic) backup this data to an XML file on disk. What would be the easiest way to implement this in visual studio? Should I create an XML schema first, or use the dataset designer? Should I bother with datasets at all or would it make sense to eliminate them and write my incoming data directly to xml?
I would recommend:
Plan a structure of an XML ahead. Create a simple empty file to help you along the way.
Create a data serialization provider as well as the interface that it will implement. In your case it will be an XML provider (who knows, you may need to save the data to a database in future. You should plan ahead for that.)
Write a custom class that serializes your poco domain objects into an xml using LinqToXML.

Best way to store small amount of data

I'm new to windows app and I would like to know what the best way to save a small amount of data, like 1 value a day.
I'm going for the text file because it's easy, but I know i could use MS Access.
Do you have other option ? Faster or better ?
Since you are already considering using a MS Access database, I would recommend using SQLite. Here's a quote from their site (SQLite Home Page):
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
It is really very easy to use - no installations required, you simply need to reference a DLL.
If you need to read it then use a plain text file.
If you need to read the values back into the application then serialize to an XML or binary file by making your user data serializable possibly by having a List of values in your object.
How do you want to use the data? Do you just want to look at it once in awhile? Do you plan to analyze it in a spreadsheet? Etc. Based upon what you say so far, I would just use a text file, one value per line. Even if later you wanted to do more with it, it's easy to import into spreadsheets, etc. If the daily data is a little more complicated (maybe a couple of different values for things each day), you might consider something like YAML.
Why stray from the path? XML gives you the ability to expand on it later without having to rethink everything.
Its mainly dependent upon the complexity of the data that you want to store. If its just DateTime some other simple built in type you would be able to recreate that object as a strongly typed one easily. But in case if its more complicated I would suggest you to create a serializable class (link on how to create such class is here) and then use one of Binary or SOAP serializations based on the size, security and other such needs. I am suggesting this as it would be best to be able to recreate objects as strongly typed ones from a flat file rather than just trying to parse what's there in the flat file.
Please let me know in case you need more clarity.
Thanks,
Sai Pavan

Read DTD or Schema and list all valid child elements or attributes for a given element

I want to develop an application something like XML editor.. providing intellisense like feature when user types an element, the application will read the DTD or schema and list the valid child elements and attributes (something like Oxygen XML Editor).
Is there an API that i can get this done?
I'm not familiar with an API that performs this task.
If you choose to implement this yourself, however, here's a couple of thoughts:
An XML schema is itself an XML file, that is structured according to the meta-schema. You can easily use one of the existing APIs to unmarshal a schema into an object structure that you can easily work with in-memory.
A DTD is not an XML structure, but any DTD can be represented as a simple schema. Therefore you should try and find a way to convert a DTD into a schema (and apply your schema solution).
HTH
You might find XSD4J useful:
XSD4J is a library to parse XML Schema
files into a structure of Java
objects, convert those back into an
XML DOM tree (and hence plain text)
again, and allow for performing
several queries on the XSD objects.
The library currently supports most
real-world features such as simple and
complex types, type restrictions and
attributes.

Categories

Resources