How do i create an RDFa definition for something like "textNode HTMLElement textNode"? - rdfa

Im trying to create some custom blocks for a CMS interface based on the symfony-cmf. In order for these blocks to be edited inline with createphp/hallo i need to create RDFa mappings for them.
The basic example for an included block is something like the following:
<type
xmlns:sioc="http://rdfs.org/sioc/ns#"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
typeof="sioc:Post"
>
<attribute key="class" value="articleContainer span3"/>
<children>
<property property="dcterms:title" identifier="title" tag-name="h2"/>
<property property="sioc:content" identifier="content" />
</children>
</type>
Which would yield something like this:
<h2>The title input</h2>
<p>the content, however i beleive the actual <p> tag is applied by the editor</p>
Thats all well and good... What Im having a hard time figuring out how to define this mapping for a resource that will be something like this:
<h1>Text string with <strong>emphasized phrase</strong> in the middle</h1>
I could probably just use the sioc:content type and then rely on the user to "bold" the emphasized phrase in the editor but i would rather have it be edited explicitly.
Is there a way to do this? Also if anyone could point me towards solid RDFa tutorials that would be great. My google-fu is usually strong but all i can seem to find are the actual spec, and a bunch of posts about seemingly unrelated usages.

The idea of the RDFa mapping is to specify which properties of the document you want to render with which tags. Actual content typically is WYSIWYG. I guess RDFa being quite complex it would support inline-nested information like what you are asking for. But the midgard/createphp component which reads this XML configuration to generate the right data does not support nested content. I am not sure if create.js would support it, but i think not.
Note that you can map children and output whole content hierarchies. But that would not handle your emphasised fragment.

Related

How to get http tag text by id using lua

There is a webpage parser, which takes a page contains several tags, in a certain structure, where divs are badly nested. I need to extract a certain div element, and copy it and all its content to a new html file.
Since I am new to lua, I may need basic clarification for things might seem simple.
Thanks,
The ease of extraction of data is going to largely depend on the page itself. If the page uses the exact same tag information throughout its entirety, it'll be much more difficult to extract than it would if it has named tags.
If you're able to find a version of the page that returns json format, then you're that much better off. Here's a snippet of code on something I wrote to grab definitions from a webpage that did not have json format:
local actualword, definition = string.match(wayup,"<html.-<td class='word'>%c(.-)%c</td>.-<div class=\"definition\">(.-)</div>")
Essentially, this code searched down the page until it found the class "word", and took the word after it (%c is the pattern for control characters). It continued on to "definition" and captured that, as well.
As you can see, it's a bit convoluted, but I had the luck of having specifically named tags for what I wanted.
This is edited to fit your comment. As a side note that I should have mentioned before, if you're familiar with regular expressions, you can use its model to capture what you need. In this case, it's capturing the string in its totality:
local data = string.match(page, "(<div id=\"aa\"><div>.-</div>.-</div>)")
It's rarely the fault of the language, but rather the webpage itself, that makes it hard to data mine anything. Since webpages could literally have hundreds of lines of code, it's hard to pinpoint exactly what you want without coming across garbage information. It's why I prefer a simplified result such as json, since Lua has a json module that can encode/decode and you can get your precise information.

Do not parse specific tags using NSXMLParser

Consider the XML below:
<root>
<bar>
<p>Hello <italic>World</italic></p>
</bar>
<banjo><p>Hello <italic>World</italic></p></banjo>
</root>
I am currently using https://github.com/nicklockwood/XMLDictionary to parse XML data. I would like to ignore <p> and <italic> tags. How can I achieve that?
NSDictionary should somehow look like this structure:
-root
--bar
---<p>Hello <italic>World</italic></p>
--banjo
---<p>Hello <italic>World</italic></p>
So a quick glance at that XMLDictionary class seems to show that it just wraps the standard NSXMLParser and creates a convenient dictionary object with the all of the XML elements.
If you are committed to that github code, then you could potentially go through your resultant dictionary after parsing the XML and restructure the <p> and <italic> elements back into the parent element. But that's pretty inefficient and definitely not recommended unless you have very short XML and the benefit of the XMLDictionary class warrants the extra work.
You could also dig into the XMLDictionary code, specifically the parser:didStartElement and parser:didEndElement methods, and make some changes to ignore the <p> and <italic> tags. This should effectively flatten the structure to something close to your example result.
But, if you're considering poking around in that code, you might as well just use the NSXMLParser directly, ignoring those tags in the same way. This will give you tighter control over parsing and could reduce some unnecessary object creation, especially if your XML is of significant size. Just read up on NSXMLParserDelegate and even walk through the XMLDictionary code to see how it does the things you like about it.

Can I use "." in POST parameter names, generated by Flash?

I'm trying to find out if a Flash application can create a POST request, where some of the names of the posted items include the "." character?
The background:
I’m working with someone who is writing a Flash application that has to POST data to the server. I'm working on the web application which receives and saves the data. As such, I know little about the inner workings of Flash myself.
To allow automated data-binding at the server (within Microsoft MVC), I want the names of the POST items to use a particular naming convention. So if I want to receive the results of two tests, I would like the POST items to use the names:
Tests[0].Score
Tests[0].Passed
Tests[1].Score
Tests[1].Passed
If this data was being submitted from a plain-old HTML form, this would be something like:
<input id="Areas_0__Score" name="Tests[0].Score" type="text" value="70" />
<input id="Areas_0__Passed" name="Tests[0].Passed" type="text" value="true" />
However, the developer says that when constructing a POST request within Flash, any items with a “.” in the name are ignored, and not included in the POST request.
Is this a known limitation of Flash, or should it be possible to include a “.” in the POST item names, as I would like?
Thanks for in advance for any ideas.
The AS3 URLVariables object used to create the post variables is a object. With falsh's syntax, something like foo.bar would mean bar is a descendent/child/property of the foo object. URLVariables are, ultimately, objects also, thus something like Tests[0].Score is not the a valid name for an object. See this example: URLVariables examples
Especially:
var variables:URLVariables = new URLVariables();
variables.exampleSessionId = new Date().getTime();
Makeing a variable like you suggest would not work because of this dot syntax used for object properties/descendants:
variables.Tests[0].Score would, to Flash, mean something like: The variables object has a property called Test[0], which has a property called Score - which makes no sense/is faulty actionscript. As Flash converts the URLVariables object with its attributes into the actual HTTP post, it fails when the attributes have attributes.

How can I custom encode/decode route values?

I have this route:
{controller}/{id}/{action}
Because I think it makes more sense from RESTful perspective.
The problem is that id can contain slashes (/) and those are treated as route separators even when encoded as "%2F". Even when I have this Web.config section in place:
<uri>
<schemeSettings>
<add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes" />
<add name="https" genericUriParserOptions="DontUnescapePathDotsAndSlashes" />
</schemeSettings>
</uri>
Because I have id in the middle I can't employ {*id} approach which captures the rest of the route including the action.
It looks like my only option is to encode / into an RFC compliant character like !, however I do not want to do it using ad-hoc custom code inside controller. I want controller to receive id intact, already decoded. And I want my Url.Action to generate properly encoded URL. Is that too much to ask from MVC, or do I need to scatter ActionFilters and custom URL helpers around?
The only way I could find is to throw in a custom IRouteConstraint to manipulate the RouteValueDictionary it receives. That sounds like a dirty hack though: a constraint manipulating its input. God knows its side effects. Do you think this is a sane enough idea, or is there a better mechanism in ASP.NET MVC allowing that?
EDIT: This workaround only works when parsing the route, not when generating one.
What you are trying to do cannot be done; this has been answered several times on SO - especially of late in relation to RavenDb which uses "/" in the Id field by default (though this can be changed)

Accessing a HashMap using Struts 2

I have hashmap that was created on a page using the struts2 <s:set> tag. It looks something like this
<s:set var="mymap" value="#request.mymap"/>
At some point in the page, i need to get a value from the hashmap based upon a key, and i want to do it using OGNL.
The key is generated based upon some logic, which i store using another <s:set> tag. Something like this
<s:set var="mykey" value="1">
I need to get a value from the hashmap using this key. And I need to display it.
How do I simply call the get function on the hashmap?
I tried this
<s:property value="#mymap[#mykey]"/>
and this
<s:property value="#mymap[%{#mykey}]"/>
and this
<s:property value="%{#mymap[%{#mykey}}]"/>
The third one obviously does not work because of the nesting problem.
But the same nesting logic is applicable to the second case as well, due to the manner the value attribute is handled. However none seem to work for me.
The issue here is that my key is unknown. It is a dynamically generated string based upon some pattern. I need to access the object stored in the hashmap using this dynamic key. And due to the inability of nesting ognl, I am in a fix.
I suppose the issue is very simple. I almost feel that I get it, but somehow the solution eludes me.
I suppose I was using a different version of struts wherein using the %{} was required for the expression to be evaluated. I changed the jar files now.
This is what did the job for me:
<s:property value="#mymap.[#mykey2]"/>
My problem was coming because I was trying to use it in a href for a s:a tag. And without the %{} operator, the expression was not being evaluated.
So, i guess, i was right in the beginning itself. Rest of the time, it was just me being silly. :>
Update:
I wrote a blog post on the issue, in case anyone is interested.
http://mycodefixes.blogspot.com/2010/11/struts-2-creating-and-accessing-maps.html

Resources