Allow custom attribute to a script tag element? - lxml

I can't validate script tag with attribute nomodule.
I am using odoo framework which is a python backend. It is using lxml to validate xml views or pages. I am building a view with a script tag like:
<script src="src.js" nomodule></script>
It returns an error
lxml.etree.XMLSyntaxError: Specification mandate value for attribute nomodule
However this should be valid according to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
Is there a way so that I can make the parser ignore this new attribute or I can bypass such as special data or character.

That's possibly because XML != HTML. And as you can see in the error, it's an XML error.
Is an xml attribute without a value, valid? --> your attribute isn't valid.

You need to specify the attribute value always in xml. Odoo uses xml to produce html, so you need to comply with xml rules. You can do it in this case by specifying an empty value for xml attribute like this:
<script src="src.js" nomodule=””></script>

Related

Is it possible to pass a JSON body along with hx-post through an attribute?

As per title, is it possible to pass a JSON body along with hx-post through an attribute? Or do I have to make it a form to pass data?
Yes, with the official json-enc extension, which "encodes parameters in JSON format instead of url format."
https://htmx.org/extensions/json-enc/
Usage
<div hx-post='/test' hx-ext='json-enc'>click me</div>

Persisting an XML element in eXist-db with CDATA content

I put the following in an xquery module declare option output:cdata-section-elements "xquery"; while trying to save a document. The element xquery is in the xpath /group/schedules/schedule/xquery and the element did not save as a CDATA. What am I missing?

Using Polymer conditional attributes with HAML

According to the documentation for Polymer expressions, you can bind data to conditionally assign an attribute using the conditional attribute syntax:
Conditional attributes
For boolean attributes, you can control whether or not the attribute
appears using the special conditional attribute syntax:
attribute?={{boolean-expression}}
That's great, but I'm using HAML where attributes are assigned to elements like this:
%element{attribute: "value"}
I can't add a question mark before that colon without HAML giving me a syntax error.
So how can I use Polymer's conditional attributes (or a functional equivalent) when I'm using HAML to generate my HTML?
One potential solution is to use the :plain filter to insert raw HTML into your HAML file:
:plain
<element attribute?={{boolean-expression}}></element>
A bit ugly, but it seems to work.
If you need to enclose some HAML-generated tags in one of these plain HTML tags, you'll need to use the :plain filter twice; once for the opening tag, and once for the closing tag.
:plain
<element attribute?={{boolean-expression}}>
-# HAML Content Here
:plain
</element>
Be sure not to indent your HAML code after the opening tag, otherwise it will become part of the "raw HTML" output and get sent as plain text to the browser instead of being processed as HAML.
The current version of HAML (4.0.6) supports conditional attributes:
%core-menu{hidden?: '{{!globals.current_series_detail}}'}
Make sure you're not putting a space before the question mark.

Get an XML Element via XPath when attributes are irrelevant

I'm looking for a way to receive a XML Element (the id of an entry) from a YouTube feed (e.g. http://gdata.youtube.com/feeds/api/users/USERNAME/uploads).
The feed looks like this:
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:yt="http://gdata.youtube.com/schemas/2007" gd:etag="W/"DUcFQncyfCp7I2A9WhVUFE4."">
<id>tag:youtube.com,2008:user:USERNAME:uploads</id>
<updated>2012-05-19T14:16:53.994Z</updated>
...
<entry gd:etag="W/"DE8NSX47eCp7I2A9WhVUFE4."">
<id>tag:youtube.com,2008:video:MfPpj7f6Jj0</id>
<published>2012-05-18T13:30:38.000Z</published>
...
I want to get the first tag in entry (tag:youtube.com, 2008 ...).
After googling for some hours and looking through the GDataXML wiki, I'm clueless because neither XPath nor GData could deliver the right element.
My first guess is, they can't ignore the attributes in the feed and entry tags.
A solution using XPath would be great, but one in Objective-C is equally welcome.
You might be having an issue trying to get XPath to work because of the default namespace.
If you just want the first tag in entry, you can use this:
/*/*[name()='entry']/*[1]
If you want the first id specifically, you can use this:
/*/*[name()='entry']/*[name()='id'][1]
Also if you can use XPath 2.0, you can skip the predicate entirely and use * for the namespace prefix:
/*/*:entry/*:id[1]

Variable in an attribute in Struts custom tag

I am trying to use a variable inside a custom Struts tag something like follows -
for(String currentMacro : (List<String>)(request.getAttribute("individualMacros"))) {
name = currentMacro.<some-operation>
<html:mce name = "hmtl_<%= name %>" />
Something like this. But <%=name%> is not replaced with the variable value. It works when I am using the variable with a pure HTML tags.
Is there any any way to accomplish this in this case?
Thanks.
Use JSP EL (assuming JSP 2.0, and you put "name" into scope). You could also check to the if the TLD allows rtexprs.
<html:mce name="html_${name}"/>
But why use scriptlets? There's rarely (ever?) a good reason.
Since we are taking about a custom tag, my guess is that in the TLD file there isn't the rtexprvalue option set to true for that particular tag attribute:
<attribute>
<name>name</name>
<rtexprvalue>true</rtexprvalue>
.......
</attribute>
The rtexprvalue specifies that the attribute value may be dynamically evaluated at runtime.
If set to "false" it means that the attribute has a static value which is evaluated at translation; if set to "true" it means the value can be determined dynamically at runtime. Default is "false".
If the scriptlet does not work, it most likely means rtexprvalue is false. If you don't have the liberty to change that, then expressions won't work on that particular attribute.