How to add new meta-property values in rdfa.rnc

249 Views Asked by At

In the RelaxNG compact-syntax schema here:

https://github.com/validator/validator/blob/master/schema/html5/rdfa.rnc#L51

…I would like to edit with some fixed rdfa attribute 'property' value in meta element.

I defined two values like:

common.attrs.rdfa.property.title = attribute property {"dct:title"}
common.attrs.rdfa.property.type = attribute property {"dct:type"}

…these two should be mandatory in meta element, how this can be done in existing rdfa common.attrs.rdfa.property list?

I am getting an error while trying to add these..

1

There are 1 best solutions below

1
On BEST ANSWER

OK, this is doable as long are you’re willing to accept some limitations. Here’s how:

In the https://github.com/validator/validator/blob/master/schema/html5/meta.rnc#L33 file, change head.inner to this:

head.inner =
        (       title.elem
        &       base.elem?
        &       common.inner.metadata
        ),
        meta.property.dct.title.elem,
        meta.property.dct.type.elem

meta.property.dct.title.elem =
        element meta { empty & meta.property.dct.title.attrs }
meta.property.dct.title.attrs =
        (       meta.attrs.property.dct.title
        &       meta.name.attrs.content
        )
meta.attrs.property.dct.title =
        attribute property { string "dct:title" }

meta.property.dct.type.elem =
        element meta { empty & meta.property.dct.type.attrs }
meta.property.dct.type.attrs =
        (       meta.attrs.property.dct.type
        &       meta.name.attrs.content
        )
meta.attrs.property.dct.type =
        attribute property { string "dct:type" }

Then the following document will cause no errors:

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta property=dct:title content=bar>
<meta property=dct:type content=bar>
</head>
<body></body>
</html>

…but any document that doesn’t have both the <meta property=dct:title content=…> element and the <meta property=dct:type content=…> element—and in that order—will cause an error.

So the biggest limitation there is that you can’t use interleave (&) but instead you need to require a specific ordering for the meta elements.

The reason for that is what’s already been explained in the questions Interleave In RNC and Can relaxng specify an unordered set of elements with the same name, but different attributes? and at https://www.oasis-open.org/committees/relax-ng/spec-20011203.html#interleave-restrictions:

The gist of it is: there’s a prohibition on interleaving definitions for elements of the same name, and it’s an intentional design restriction added to RelaxNG to make implementation more feasible.

So the above (re)definition of head.inner says that an HTML head element is allowed to have:

  • an interleave of:
    • a required title element
    • an optional base element
    • common.inner.metadata, which is any amount of script, noscript, template, style, link, and meta elements
  • followed by a required meta element with a property=dct:title attribute
  • followed by a required meta element with a property=dct:type attribute

I think that’s the closest you’re going to get to what you want, as long as you’re using RelaxNG.

Another limitation of it is, it won’t give you very helpful error messages if one of those is missing.

Instead you’ll just get this:

head is missing a required instance of one or more of the following child elements: meta

That is, it won’t (well at least jing won’t) tell you the one you’re missing has property=dct:type.

When declaring this I am getting something like data and string error

I think you were having that problem because you were doing this:

common.attrs.rdfa.property.title = attribute property {"dct:title"}

…when what you need to be doing instead is this:

common.attrs.rdfa.property.title = attribute property {string "dct:title"}

…that is, you need to specify the string keyword there.

But anyway, making changes to common.attrs.rdfa.property would never get you what you want as far as requiring documents to have both <meta property=dct:title content=…> and <meta property=dct:type content=…> elements.

All that making changes there would have gotten you (if it you could get past the syntax problems) is, it’d allow specific dct:title and dct:type values for the property attribute.