Can I get ServiceStack to serialize specific properties as XML attributes instead of elements? - xml-serialization

My ServiceStack API is returning the following XML:
<UserResult>
<Email>dan-dare#the-eagle.com</Email>
<Forenames>Daniel</Forenames>
<Href>/users/00000001-0000-0000-0000-00000000000d</Href>
<Memberships>
<Href>/users/00000001-0000-0000-0000-00000000000d/memberships</Href>
</Memberships>
<Surname>Dare</Surname>
<UserGuid>00000001-0000-0000-0000-00000000000d</UserGuid>
<Username>test_dan</Username>
</UserResult>
I'm curious as to whether I can modify the XML serialization so it returns the HREF properties as attributes rather than elements:
<UserResult href="/users/00000001-0000-0000-0000-00000000000d">
...
<Memberships href="/users/00000001-0000-0000-0000-00000000000d/memberships" />
...
</UserResult>
or even override the default serialization entirely so that particular properties are exposed as <link /> elements:
<UserResult href="/users/00000001-0000-0000-0000-00000000000d">
...
<link rel="memberships" href="/users/00000001-0000-0000-0000-00000000000d/memberships" />
...
</UserResult>
I'm undecided as to whether I should do this, but very curious to know whether it's possible - either by decorating the properties or by replacing the default XML serializer (DataContractSerializer?) used by ServiceStack.

Related

Can value in PropertyValue be an array? [duplicate]

A Schema.org object of type Person can have a sameAs property of type URL. According to Google's structured data site, the sameAs property can be a single item or an array.
The docs on Schema.org do not mention whether sameAs can be a single item or an array. Is this just Google deviating from Schema.org? Or is it the case that all properties in Schema.org can be single items or arrays?
Every Schema.org property can have multiple values. It doesn’t necessarily make sense for some properties (e.g., birthDate), but it’s still allowed.
In JSON-LD:
"sameAs": ["/foo", "/bar"],
In Microdata:
<link itemprop="sameAs" href="/foo" />
<link itemprop="sameAs" href="/bar" />
In RDFa:
<link property="sameAs" href="/foo" />
<link property="sameAs" href="/bar" />
This doesn’t necessarily mean that Google (or any other consumer) supports this for every property, too. So when Google explicitly mentions this in their documentation, you can be sure that the respective search result feature works with multiple values.

How to define multiple dietary restrictions in suitableForDiet field? [duplicate]

A Schema.org object of type Person can have a sameAs property of type URL. According to Google's structured data site, the sameAs property can be a single item or an array.
The docs on Schema.org do not mention whether sameAs can be a single item or an array. Is this just Google deviating from Schema.org? Or is it the case that all properties in Schema.org can be single items or arrays?
Every Schema.org property can have multiple values. It doesn’t necessarily make sense for some properties (e.g., birthDate), but it’s still allowed.
In JSON-LD:
"sameAs": ["/foo", "/bar"],
In Microdata:
<link itemprop="sameAs" href="/foo" />
<link itemprop="sameAs" href="/bar" />
In RDFa:
<link property="sameAs" href="/foo" />
<link property="sameAs" href="/bar" />
This doesn’t necessarily mean that Google (or any other consumer) supports this for every property, too. So when Google explicitly mentions this in their documentation, you can be sure that the respective search result feature works with multiple values.

Converting XSD to ECore

I am currently trying to convert an XML Schema to ECore with the Eclipse Modeling Framework. EMF offers the attributre ecore:reference to indicate that an attribute should be translated into an EReference. However, this only works if the attribute is of type IDREF or anyURI. My problem is that any ID referenced via IDREF has to be unique througout the whole XML document. However, my XML has the following structure:
<A id="a1">
<B id="b1">
<ref idref="b2" />
</B>
<B id="b2">
<ref idref="b1" />
</B>
</A>
<A id="a2">
<B id="b1">
<ref idref="b2" />
</B>
<B id="b2">
<ref idref="b1" />
</B>
</A>
The ids of the B-elelemts are only unique inside the sourrounding A-element. Thus the parser will throw an error if i declare the ids of the B-elements as type ID.
How can I tell EMF that idref is a reference to the attribute id of B-element which belongs to the same A-element?
If the XML Schema is really using ID and IDREF, then the instance you show isn't valid with respect to that schema. Isn't that a problem? It's more like a key/keyref, which isn't supported by Ecore either.
If it just comes down to wanting an Ecore model that can read and write such instances I would define an attribute idref that's just a string and define a transient reference resolvedRef of type A and I'd modify the getters and setters so that each derives sensibly from the other. I.e., when you call getResolvedRef, it would check if the field for that is null, and if the field for the idref has a value, it would walk the model to resolve (look up that name in the appropriate scope) and store it in the field.
It's a bit tricky to define the mutual derivation in a sensible way for both getters and both setters, but it should be possible.

Creating a GeoPoint complex data type in Facebook Open Graph

I am attempting to create a GeoPoint type to my existing Object. Facebook's documentation here isn't exactly stellar - but what I went ahead and did was create a new property and named it location. I made it of type GeoPoint and required.
I then supply the following in my template:
<meta property="my-app:location:latitude" content="<%= #location.lat %>" />
<meta property="my-app:location:longitude" content="<%= #location.lng %>" />
Yet the debugger complains:
The parser's result for this metadata did not match the input metadata. Likely, this was caused by the data being ordered in an unexpected way, multiple values being given for a property only expecting a single value, or property values for a given property being mismatched. Here are the input property =>content pairs that were not seen in the parsed result: 'my-app:location:latitude => 40.134537901957735, my-app:location:longitude => -75.00853989318185'
How am I supposed to define this GeoPoint and how am I supposed to embed the lat/lng in my URL? This does not want to validate it any way I've tried.
I just ran the URL of an object I published via another app (Endomondo), but which contains GeoPoint data into the debug tool, and this is how they did it. Bear in mind it's an array in this case (it's a path for a cycle activity) so there were actually like 60 of these, but i think a single example would just be:
Meta Tag <meta property="endoapp:route:latitude" content="3x.xxxx" />
Meta Tag <meta property="endoapp:route:longitude" content="-12x.xxxx" />
Meta Tag <meta property="endoapp:route:altitude" content="0.01" />
Looking at your example, I think maybe the omitted altitude could be the problem?
Endomondo's example uses an array of points in the 'route' field, and one each for start and finish, which are endoapp:start:latitude, endoapp:start:longitude, etc
You should omit what you specified at
property="og:type", i.e. content="my-app"
if so then you should use property="location:latitude" etc (omit "my-app" prefix)

Sharepoint 2007 - Custom List provisioning - are List Forms needed at deployment?

I have a feature which is provisioning 1 document library and 2 custom lists. A folder is included for each list containing the schema.xml for that list. Each folder also contains the associated forms (AllItems, DispForm, EditForm, NewForm, etc.). Everything deploys/works correctly but it seems a little redundant having the same forms copied into each list's folder. There is nothing special about these lists - the are basically a default doc library/generic list with additional fields provided through new content types (derived from Item/Document).
As far as I can tell these forms are pretty generic. Are there pre-installed forms that I can reference from my list so I don't have to deploy all of these extra files? Is there any reason I would not want to do this?
Update - moving xml in comment to original question for readability:
<Forms>
<Form Type="DisplayForm" Url="Forms/DispForm.aspx" WebPartZoneID="Main"/>
<Form Type="EditForm" Url="Forms/EditForm.aspx" WebPartZoneID="Main"/>
<Form Type="NewForm" Url="Forms/Upload.aspx" WebPartZoneID="Main"/>
<Form Type="NewFormDialog" Path="EditDlg.htm">
....
There are virtual defaults that are used if you don't specify a concrete page.
All lists use these template defaults unless you use a tool like SharePoint designer to customize the page. Then the template is used to create the concrete page and you can customize the look for a particular list without affecting others.
For my custom definitions, I use
<List>
...
<MetaData>
...
<Forms>
<Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
<Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
<Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
</Forms>
</MetaData>
</List>
If you have no reason to customize the out of the box version of these forms, you can use the virtual form and not deploy copies.