how to call getNamedItem() and nodeValue() of DOMDocument within function - domdocument

I have an XML to import using DOMDocument. To avoid lot of foreach loop used to retreive nodeValue (), I used it as separate function. It is not working for me in live server. The function is as follows:
<?php
function Single_ParseDomObjXML($parameter){
$value='';
foreach($parameter as $get_val)
{
$value=$get_val->nodeValue;
}
return $value;
}
$text_tags=$events->getElementsByTagName('text');
foreach($text_tags as $text_inf){
$event['text']['promo']=Single_ParseDomObjXML($text_inf->getElementsByTagName('promo'));
$event['text']['spec']=Single_ParseDomObjXML($text_inf->getElementsByTagName('spec'));
$event['event_desc']=nl2br(Single_ParseDomObjXML($text_inf->getElementsByTagName('desc')));
}
?>

Related

Vaadin 14: sending data from a web component to server

How can i send data from client to server using html5 webcomponent
setting up data from server to client, is very easy, works like a charm
how ever cannot find solution to send data to server
Please assist, but Iam not going to use Lit or Polymer
#JavaScript
class SimpleComponent extends HtmlElement {
connectedCallback() {
this.innerHTML = '<input type="text" id="test"/>";
this._input = this.querySelector('#test');
this._input.onchange = function() {
***** i want to send the value to server ****
})
}
setInputValue(value) {
this._input.value = value;
}
}
customElements.define("simple-com",SimpleComponent);
Now Java at Server
#Tag("simple-com")
class SimpleComponent extends Component {
public SimpleComponent() {
}
public void setValue(String value) {
getElement().callJsFunction("setValue",value);
}
}
The main challenge compared to Polymer or LitElement is that an event handler defined using the pattern innerElement.onchange = function() {} will not be run with this referencing the custom element instance. This in turn means that trying to use this.$server won't work because this isn't pointing to the expected value even though $server is indeed present in the place where it's supposed to be.
The easiest way of fixing this is to change the code to use an arrow function (() => {}) instead of an explicit function. This works because arrow functions inherit this from the scope where the function is defined whereas explicit functions have this defined in different ways depending on how it is run. Another approach would be to store a reference to this in a separate variable (e.g. let root = this) and then reference that variable instead of this in the function (e.g root.$server.doSomething()).
Putting everything together, this is what the code looks like with my modifications to make everything work.
class SimpleComponent extends HTMLElement {
connectedCallback() {
this.innerHTML = '<input type="text" id="test"/>';
this._input = this.querySelector('#test');
this._input.onchange = () => {
this.$server.handleChange(this._input.value);
};
}
setValue(value) {
this._input.value = value;
}
}
customElements.define("simple-com", SimpleComponent);

how to require multiple files to a component within a react native app

I am trying to require multiple images from a folder within my react native project. I am trying to dynamically load the images I need to render an animation with a react-native-image-sequence component in another react component. I know you can only require images by only passing a string in react-native like this: require("../somepath"), so I am trying to find a work around to load multiple images by passing in a dynamic path. I need to be able to pass the image sequence component an array like this:
[ require("./1.png"),
require("./2.png"),
require("./3.png")
]
for it to render the animation sequence.
I have tried creating a file that contains a method called prepareDirImages that creates and returns a string that contains an array full of require statements to the path passed in as well as the extension of the file. My plan was to then use this method in the component that I am creating and calling eval(prepareDirImages("./dirPath", "png")) to transform the string into its actual array representation and then passing this into the image sequence component.
prepareReactImages.js:
module.exports = {
prepareDirImages(path, ext){
fs.readDir(path).then(files => {
const ex =
"[\n" +
files.map((x, index) =>{
if(index < result.length - 1){
return `require("${path}/${x}"),`
}
`require("${path}/${x}")`
}).join("\n") +
"]";
console.log(ex)
fs.writeFile("../images/index.js", ex);
return ex;
})
}
}
myComponent.js:
import React, { Component } from 'react';
import ImageSequence from 'react-native-image-sequence';
import { prepareDirImages } from '../services/prepareReactImages';
import { View, Text } from 'react-native';
const fs = require('react-native-fs');
export default class myComponent extends Component {
render(){
console.log(eval(prepareDirImages("../images/imagesDir", "png")))
let images = getImages();
return (
<View>
<ImageSequence
images={images}
style={this.props.style}
framesPerSecond={24}
/>
</View>
);
}
}
async function getImages(){
return eval(await prepareDirImages("../images/ed_anim_wave_v01",
"png"))
}
What I get is a promise and I get an error saying that imagesequence cant using property filter of object. I read that you have to use fs.MainBundlePath or fs.DocumentDirectoryPath but I dont understand how to get these files. If anyone can help me out, I'd appreciate it tremendously!!

How do I create a global (on the window) object in Dart lang?

Let's say I want to create a global object called Hello and add the function world on that object, so that any other JavaScript library in the browser can simply call it with window.Hello.world();
How do I create such an object in Dart lang and how do I expose it / place it globally / on the window object?
In plain JavaScript, I would be able to write:
window.Hello = {
world: function() {
console.log("Hello World!");
}
}
window.Hello.world();
But how do you do this in Dart?
I work on Dart-JS interop. Here is the cleanest way to do it using the new package:js/js.dart interop.
#JS()
library your_library;
import 'package:js/js.dart';
#anonymous
#JS()
class HelloObject {
external factory HelloObject({Function world});
external world();
}
#JS()
external set Hello(HelloObject v);
#JS()
external HelloObject get Hello;
main() {
Hello = new HelloObject(world: allowInterop(() { print("Hello from dart"); }));
// You can also call this object from Dart as an added bonus.
// For example you could call this from Dart or Js.
/// Hello.world();
}
I am not sure how it will work with objects, but if you want to do that for methods, it's quite simple:
import 'dart:js' as js;
main() {
js.context['methodFromDart'] = doMyStuff;
}
void doMyStuff(String text) => print(text);
And then in you Javascript you are free to do:
methodFromDart("Hello world to Dart!");
You can try to find a way how to do similar things to objects.

How to use each function, this from jquery to Dart Language?

I have a function in jquery as below
function findMax(){
$( ".elements" ).each(function( ) {
if($(this).css('z-index')>max1)
max1=$(this).css('z-index');
max1=parseInt(max1);
});
}
I have to implement this function in Dart Language. Facing problems with syntaxes in using .each function and 'this' function.
The equivalent of jQuery :
$(".elements").each(function( ) {
// do something with this being one of elements with a 'elements' class
// you can access the current element with $(this)
});
is in Dart :
querySelectorAll('.elements').forEach((Element e) {
// do something with e being one of elements with a 'elements' class
// you can access the current element with e
});

how do I add custom function to zepto?

New to zepto (and honestly, far from a jQuery-whiz),
I want to add a custom function.
This is my attempts so far:
//define..
$.fn.doSearch = function() {
alert(this.parentNode.html());
//now xhr..
}
//assign..
$('#resetBtn').click( function (e) {$(this).doSearch()});
and
//define
<script type="text/ja..
function doSearch(obj) {
alert('Ugly way but here I am');
}
//assign..
$('#resetBtn').click( function (e) {window.doSearch()});
And neither works.. I'd rather go the first route, aware that .fn isn't listed in the zepto-docs.
regards,
//t
ok, now I have
//define
var myFunc = {
doSearch: function(obj) {
//just check obj is ok.
alert($(obj.parentNode).html());
}
}
//correct way to extend zepto?
$.extend($,myFunc);
//assign...
$('#searchBtn').click( function (e) {$(this).doSearch(this)});
is this the way to go?
As mentioned in the documents,
(function($){
$.extend($.fn, {
foo: function(){
// `this` refers to the current Zepto collection.
// When possible, return the Zepto collection to allow chaining.
return this.html('bar')
}
})
})(Zepto)

Resources