Is there any requirement for DOM used to create a DominoTree, such as being namespaceaware or created with level 2 dom builder? - dom

We are adding code to convert a DOM to Domino before invoking saxon library to process xquery expression, which involves constructing a xml document as output.
Following exception is seen, for DOM created using certain DOM builders:
java.lang.NullPointerException
at net.sf.saxon.om.NameOfNode.equals(NameOfNode.java:177)
at net.sf.saxon.om.SingletonAttributeMap.put(SingletonAttributeMap.java:69)
at net.sf.saxon.om.NodeInfo.attributes(NodeInfo.java:528)
at net.sf.saxon.tree.util.Navigator.copy(Navigator.java:673)
at net.sf.saxon.om.NodeInfo.copy(NodeInfo.java:568)
at net.sf.saxon.tree.util.Navigator.copy(Navigator.java:679)
at net.sf.saxon.om.NodeInfo.copy(NodeInfo.java:568)
at net.sf.saxon.event.ComplexContentOutputter.decompose(ComplexContentOutputter.java:860)
at net.sf.saxon.event.ComplexContentOutputter.append(ComplexContentOutputter.java:656)
The cause seems to be that node.getLocalName() for attribute type of nodes, returns null for Domino. Same setup works if DOM is converted to Tiny Tree or passed using a DOMWrapper to Saxon.
Xquery using domino, expected to work, threw Exception.

You've raised this on the Saxonica support forum at https://saxonica.plan.io/issues/5727
To summarise:
(a) Whether using the DOM wrapper in Saxon, or the Domino structure (which adds extra indexing), the DOM should be namespace-aware and should be constructed using namespace-aware (i.e. level-2) interfaces.
(b) If you don't follow that rule, we shouldn't crash (so we'll fix the crash that you've observed), but we can't guarantee delivering XPath-conformant results. The mapping from a non-namespace-aware DOM to a valid XDM instance is undefined and unpredictable, so the results of XPath processing are undefined. This might mean, for example, that when the result is serialized, it's not well-formed XML (for example, it might contain undeclared prefixes in element or attribute names.

Related

Node.CloneNode() not a function -dom-to-image.js

I want to create a .png file of a HTML page in angularjs and download it. For this I'm currently using dom-to-image.js and using the domToImage.toBlob function and passing the node element to it. But internally when it goes to dom-to-image.js it throws the error:
node.cloneNode() is not a function
Can anyone please assist me here?
Thanks
This error arises when you attempt to call cloneNode() on anything other than a single DOM node.
In this case, the error is coming from the dom-to-image library, which calls that method internally.
Note that without a code snippet, its hard to identify the precise issue with your code, but the point is, when you call domtoimage.toBlob(), you need to supply a single DOM node.
So double check what you are calling it with. If you are selecting by class, for instance, you could end up with more than one element.
Its best practice to be precise with which node you want to convert to a blob - use the id attribute, like this:
domtoimage.toBlob(document.getElementById('element')).then(...)
where element is the id of your target node.
Its also possible you're selecting with angular.element() or even using jQuery directly.
In both cases, this returns an Object -- which you can't call cloneNode() on.
Also note the following from the Angular docs for angular.element():
Note: All element references in AngularJS are always wrapped with jQuery or jqLite (such as the element argument in a directive's compile / link function). They are never raw DOM references.
Which means you would observe the same behavior in both cases, e.g. both of these:
domtoimage.toBlob($('#element')).then(...)
domtoimage.toBlob(angular.element('#element')).then(...)
would result in the error you see. You can index the Object before supplying it to domtoimage.toBlob(), perhaps like this:
domtoimage.toBlob($('#element')[0]).then(...)
domtoimage.toBlob(angular.element('#element')[0]).then(...)
and that would also work.
Also check out this post about "cloneNode is not a function".

Testcafe Selector to identify element inside the specific component of DOM Structure

How to convert the below Relative path to TestCafe Selector?
//a[contains(#name,'indent')]/parent::div//span[contains(text(),'Follow')]
If I try the above one, it recognizes specific DOM Component which contains multiple elements and one of those is 'Follow'.
how to achieve this using TestCafe Selectors.
I did not succeeded with the below one :
Selector('a').withAttribute('#name','indent').parent('div').child('span').contains('Follow')
Selector('a').withAttribute('#name','indent').parent('div').child('span').withText('Follow')
I checked your code and found a couple of possible causes, which can lead to the issue.
TestCafe Selectors do not have the contains method so the first example is incorrect.
Though I don't know your html structure, I can currently assume that there is no need to pass the # char in the attribute argument.
Thus your second example looks valid excepting the # char.
If this recommendation does not help, please provide us with a working example that shows the issue and create a separate bug report in the TestCafe repository using the following form

Toomany DOM updates

The link [https://ccamel.github.io/playground-binding.scala/index.html#playground-binding.scala/home]
has few demos of binding.scala
I have used DomListner extension in chrome to understand the dom events.
I found for each interaction there are hundreds of DOM events fired.
For example one click on calculator button results in 114 events.
It this a performance issue ?
Does binding.scala library need performance improvements ?
Does the code written using binding.scala need optimization ?
It's the expected behavior, because the DEMO that you mentioned recreated anchor elements, explicitly.
According to the Scaladoc for bind method:
Each time the value changes, in the current #dom method, all code after the current bind expression will be re-evaluated
As a result, the calc.bind call at here forces recreating the anchor element.
I created a pull request to change the class attribute instead, by avoiding the calc.bind call before XHTML literals.

removing a div element with coffeescript

I want to remove a div element with a specific class attribute using Coffeescript. I couldn't find any examples about DOM manipulation with Coffeescript on the Internet. How can I do this? Also any references to doing DOM would be great.
CoffeeScript is a JavaScript preprocessor, there is no additional standard library. What this means is that if you want to do DOM manipulation you would do it the same way you would in JavaScript.
You can use any JavaScript library like jQuery with CoffeeScript, alternatively you can use the document variable directly:
element.parentNode.removeChild(element) for element in document.getElementsByClassName('some-class')
Or (for browsers not supporting that method)
element.parentNode.removeChild(element) for element in document.getElementsByTagName('*') when element.className = 'some-class'
Or, since those identifiers are somewhat long, use block syntax:
for element in document.getElementsByTagName('*')
if element.className is 'some-class'
element.parentNode.removeChild(element)
Relevant quote from CoffeeScript.org:
The golden rule of CoffeeScript is: "It's just JavaScript". The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa).
#lauren's answer works for me but when I'm using chrome, I'm getting the following error:
Uncaught TypeError: Cannot read property 'id' of undefined
Using the following works perfect, tested on Chrome.
$(document).on 'hidden.bs.modal', "#newProject", ->
document.getElementById("<ID>").outerHTML=''
delete element
From:
https://stackoverflow.com/a/19298575/5452072

Issue: Action redirect do not include parameter as complex objects in Struts2?

I have tried an example in which i have inserted a user using insert method of UserAction class.
On insert I have redirected the success to loadAdd method of UserAction.
During redirect I have passed the parameter as
${user}
In struts 2.0.14 this gives an ognl exception.
whereas when I pass
${user.id}
it works.
My observation says this is a bug in struts or ognl that it does parse composite objects while it parses simple data types.
Any work-around please suggest.
Or
Is there any way by which I can forward the complete action context or value stack in the redirected action
It's not a bug.
Struts2 uses a type conversion system to convert between Strings (native HTTP) and other objects. It has default type converters for all of the standard primitives, boxed primitives, collections, maps, etc. If you want to allow Struts2 to automatically convert between a string and your User class, you need to create a type converter for it. Otherwise, you can use ${user.id}, which is a primitive or boxed primitive.
http://struts.apache.org/2.2.3/docs/type-conversion.html
Also, the ValueStack is per-request, so when you redirect and create a new request, the previous requests ValueStack is no longer available.