Using Boost.Serialization to parse a custom XML format - c++

I have a custom XML format that needs to be serialized to objects.
I only need to serialize certain tags and ignore the rest.
I have the impression that I need to write my own archive class but there is no documentation that explains how can it be done.
I do not need to save anything, just load the initial state of the object.
Anyone got a pointer for me?

Related

Can I Access one document's data from another document in mfc

Im trying to make new doc type in mfc that reads data from another document type when needed. And my question is- Is this possible and how it should be done ?
You can use CWinApp::GetFirstDocTemplatePosition() and CWinApp::GetNextDocTemplate() to iterate through the doc templates.
Then, for each doc template, use CDocTemplate::GetFirstDocPosition() and CDocTemplate::GetNextDoc() to iterate through the documents.
You will need to make the document data public or provide getters/setters.

How to use Openlayer refresh strategy with django-olwidget?

I would like to have "realtime" like map.
My main question is:
How to use django-olwidget with openlayers OpenLayers.Strategy.Refresh?
Do I need to start back "from scratch" to use manually openlayers?
With django-olwidget, the data is on the web page so the args which define data-source, protocol.
My "second" question is about which format should I choose...
geoJSON? kml? other?
Can those formats contain openlayers point specific "style" specifications like:
{'graphic_name': 'square', 'point_radius': 10, 'fill_color': "#ABBAAB', 'stroke_color':'#BAABBA'}.
I already overriden the default map template olwidget/multi_layer_map.html to access my map object in JS. I think it should be rather simple to apply a js function on each data layers before passing it to the map.
Thanx in advance.
PS: I'm french speaker.
PS2: I asked this question as a feature request on github: https://github.com/yourcelf/olwidget/issues/89
If you're going to use regularly-refreshing data (without refreshing the page) and serialization formats like geoJSON and KML, django-olwidget won't help you very much out of the box. You might find it easier just to use OpenLayers from scratch.
But if you really wanted to use django-olwidget, here's what I would do:
Subclass olwidget.InfoLayer to create a new vector layer type that uses a network-native format like geoJSON or KML to acquire its data.
Add a corresponding python subclass to be able to use it with Django forms or whatever the use case is. You'll probably need to specify things like the URL from which the map will poll its data.
This is a lot of work beyond writing for OpenLayers directly. The advantages would be that you would get easy Django form integration with the same map.
As to which serialization format to use: I'm partial to JSON flavors over XML flavors such as KML, but it really doesn't matter much -- Django and OpenLayers both speak both fluently.
About the styling,you should take a look at the StyleMap[1] where you can set style properties according to attributes.
For the main question, I’m sorry I don’t know django-olwidget…
1 - http://openlayers.org/dev/examples/stylemap.html

How do i create a REST service that accepts a List of objects from a client and how do i create the client.

i am trying to create a REST service that accepts a List of objects from a client and gives back a zip file.
i understand how to give back the zip file alright.
But i am right now trying to figure out a way i can pass a List of objects from a REST client/browser to the Rest service and how do i accept the List in the REST service.
Should this be done via XML input ?
or maybe the #consumes annotation could help?
Much thanks .
Som
You need to think out more clearly what you wish to do. There's no really good reason for taking a list of objects and returning a ZIP of them; you might as well use a local zip program (which just about all computers already have). That indicates that we instead need to be looking at something sensible: for example, a list of names of objects that you'll return a ZIP of, that makes a lot of sense. There are other sensible things you could be doing too, but you have to work it out in your mind what you want to happen.
Because you mention “#consumes annotation”, I'm going to assume you're using JAX-RS (i.e., Java). That's nice, because it's entirely possible to do on-the-fly ZIP generation with that; the content type you want to produce is application/zip. The easiest way I've found to handle the specification of the list of descriptions of things to return is as a wrapped list, where you use something like JAXB to do the mapping (which gives you XML support; some frameworks also support JSON off the same data models). To do a wrapped list, you use something like this:
#XmlRootElement
public class Wrapper {
#XmlElement
public List<String> item;
}
That then produces/handles XML documents like this (a three item list):
<wrapper>
<item>foo</item>
<item>...</item>
<item>bar</item>
</wrapper>
You'll need to set up the #Consumes annotation so that the content type accepted is application/xml (at least), and also consider what type of operation is involved and on what resource.
[EDIT]: In order to create a REST service that takes a list of strings as arguments, the easiest method is indeed to use a wrapper object, much as above. (You can't take a raw list; it needs to be a well-formed XML document when it's on the wire.) We then set up the annotated service method like this:
#POST
#Path("somewhere/{id}")
#Consumes("application/xml")
#Produces("application/zip")
public Response getSomeBytesForList(#PathParam("id") String id, Wrapper req) {
List<String> items = req.item; // For example...
byte[] zip = generateZipBytes(id, items); // or however
return Response.ok(zip).type("application/zip").build();
}
The key is that the req argument (the name is arbitrary, of course) is the only argument that is not annotated, that it is of a type that is JAXB-enabled, and there is an overall #Consumes ("application/xml") annotation to enable the JAXB processing of the request body. (I handle the returning of a ZIP by generating the Response directly rather than relying on the framework to do the processing for me; this lets me control the content type handling a little more precisely.)
Also note that some frameworks can also transfer JAXB-annotated objects as JSON documents, just by having a bit of extra annotation; you just state that the method can accept both "application/xml" and "application/json" in the #Consumes annotation. I do not know whether this applies to the framework you are using (I've only tested it with Apache CXF).

Read/Load multiple XML in a single test initialize with NDbUnit

I am trying to use the NDbUnit. I have created seperate XSD for each table instead of one large XSD for complete database.
My tests run fine when I use only single XSD and singe xml read. However for a perticular test, I need to have data in two or three different (but related) tables. If I try to read more than one xsd and xml, then it throws exception.
Here is my code
[ClassInitialize()]
public static void MyClassInitialize(TestContext testContext)
{
IDbConnection connection = DbConnection.GetCurrentDbConnection();
_mySqlDatabase = new NDbUnit.Core.SqlClient.SqlDbUnitTest(connection);
_mySqlDatabase.ReadXmlSchema(#"Data\CompanyMaster.xsd");
_mySqlDatabase.ReadXml(#"Data\CompanyMaster.xml");
_mySqlDatabase.ReadXmlSchema(#"Data\License.xsd");
_mySqlDatabase.ReadXml(#"Data\License.xml");
_mySqlDatabase.ReadXmlSchema(#"Data\LicenseDetails.xsd");
_mySqlDatabase.ReadXml(#"Data\LicenseDetails.xml");
_mySqlDatabase.ReadXmlSchema(#"RelatedLicense.xsd");
_mySqlDatabase.ReadXml(#"Data\RelatedLicense.xml");
}
Here is the exception I get at the point where i try to read License.XSD as shown above
Class Initialization method
ESMS.UnitTest.CompanyManagerTest.MyClassInitialize
threw exception.
System.ArgumentException:
System.ArgumentException: Item has
already been added. Key in dictionary:
'EnableTableAdapterManager' Key being
added: 'EnableTableAdapterManager'.
I am not sure if this is the correct way of reading multiple XML,XSD with NDbUnit. I googled and Overflowed (i.e. searched stack overflow), but could not get any sensible direction. Could someone explain what is going wrong and how to correct?
This isn't how NDbUnit is intended to be used. There is no support for reading multiple XSD or XML files into a single test-scope. NDbUnit uses the information in the single XSD to analyze relationships (FKs, etc.) between your tables in order to be able to properly manipulate the tables during its CRUD operations and so the requirement is that the single XSD describe the entire scope of the tables that you want NDbUnit to manipulate during a test-run.
It might be possible to load multiple XML files (containing your test data) but this is not a tested/supported scenario. I'd be interested in understanding what usage scenario you have that would preclude having just one XML file with your needed test data.
But its definitely the case that only a single XSD file (containing the schema of one or more tables and their relationships, etc.) can be loaded at a time.
Hope this clears this up a bit.
Sbohlen showed me the way.
It's true that as thing stands as of now, loading of multiple XSD's is not supported.
However fortunately loading of multiple XMLs against single XSD is possible.
So what I did was created a single XSD and pulled in all related tables onto it. Then used the AppendXml sytanx available along side of ReadXml. This way I could load the required test data into multiple tables and my tests started getting passed.
This link would share more lights about the AppendXml http://code.google.com/p/ndbunit/issues/detail?id=27

Pitfalls of generating JSON in Django templates

I've found myself unsatisfied with Django's ability to render JSON data. If I use built in serializes then database foreign key relationships are not included in the data (only the keys). Also, it seems to be impossible to include custom data in the json feed that isn't part of the model being serialized.
As a test I implemented a template that rendered some JSON for the resultset of a particular model. I was able to include/exclude whatever parts of the model I wanted and was able to include custom data as well.
The test seemed to work well and wasn't slower than the recommended serialization methods.
Are there any pitfalls to this using this method of serialization?
While it's hard to say definitively whether this method has any pitfalls, it's the method we use in production as you control everything that is serialized, even if the underlying model is changed. We've been running a high traffic application in for almost two years using this method.
Hope this helps.
One problem might be escaping metacharacters like ". Django's template system automatically escapes dangerous characters, but it's set up to do that for HTML. You should look up exactly what the template escaping does, and compare that to what's dangerous in JSON. Otherwise, you could cause XSS problems.
You could think about constructing a data structure of dicts and lists, and then running a JSON serializer on that, rather than directly on your database model.
I don't understand why you see the choice as being either 'use Django serializers' or 'write JSON in templates'. The middle way, which to my mind is much more robust and fits your use case well, is to build up your data as Python lists/dictionaries and then simply use simplejson.dumps() to convert it to a JSON string.
We use this method to get custom JSON format consumed by datatables.net
It was the easiest method we find to accomplish this task and it looks very fine with no problems so far.
You can find details here: http://datatables.net/development/server-side/django
So far, generating JSON from templates, we've run into the need to escape newlines. Looking at doing simplejson.dumps() next.