Can't retrieve elements with xpath from an OpcUa Nodeset - node.js

I am trying to query with xpath this XML file (https://github.com/OPCFoundation/UA-Nodeset/blob/master/Robotics/Opc.Ua.Robotics.NodeSet2.xml).
I am trying to get all the elements inside the tag "UANodeSet" but I always get an empty return.
I am working with node js
Here it is my code:
nodes = fs.readFileSync(Nodeset+".xml", "utf-8");
var data = xpath.select("//UANodeSet", nodes)
fs.writeFileSync("./data.xml" , data);
The library that I am using comes from npm and it is called xpath.
The expectation is having all the child elements inside UANodeSet, reality is that I am having an empty return.
Do you know how to solve it?
Sorry, first time working with xpath.
Ok, first problem is done.
Now I am trying to retrieve all the UAObjectType, but it seems like the xml output is really wrong foermatted and I donĀ“t know why.
Here it is the code:
var select = xpath.useNamespaces({"ns" : "http://www.w3.org/2001/XMLSchema-instance" , "ns1" : "http://opcfoundation.org/UA/2011/03/UANodeSet.xsd" , "ns2" : "http://opcfoundation.org/UA/2008/02/Types.xsd", "ns3" : "http://www.siemens.com/OPCUA/2017/SimaticNodeSetExtensions" ,"ns4" : "http://www.w3.org/2001/XMLSchema" });
var data = select('//ns1:UAObjectType' , ns)
fs.writeFileSync("./data.xml" , data);
Does anyone knows how to solve it?

The xml file uses namespaces and that seems to trip up the xpath expression. Try something like this and see if it work:
dom = require('xmldom').DOMParser
var doc = new dom().parseFromString(nodes)
var targets = xpath.select("//*[local-name()='UAObject']", doc)
The other solution is:
var select = xpath.useNamespaces({"ns1" : "http://opcfoundation.org/UA/2011/03/UANodeSet.xsd" });
var data = select('//ns1:UAObjectType' , ns)

Related

Can not delete or update error in postman express mongoose

I have written a code to update and delete with json and testing with postman it shows like below
here is my code
please give me a solution for this matter..
the req.params. should be the same like you write it in the path ("../:id")
so your code must be like this : let noticeId = req.params.id
or you change the path like this : router.route('/deleteNotice/:noticeId') and keeping this : let noticeId = req.params.noticeId
Could you show your routing
And after that, change your define noticeId to let noticeId = req.params.id
Because of you defined the route is /deleteNotice/:id with id is your params

How to get the id from the given lines of code?

{
acknowledged: true,
insertedId: new ObjectId("612d9d08db9c20f031033478")
}
This was the JSON format I got while I added a file and some other things to MongoDB and I want to get this id separately to save the file to another folder.
Can anyone please explain this?
I believe this question was answered by Vikas in this thread How to get value from specific key in NodeJS JSON [duplicate]
Edited The Answer. Now Its working for above object in question
You can use following function to access the keys of JSON. I have
returned 'mm' key specifically.
function jsonParser(stringValue) {
var string = JSON.stringify(stringValue);
var objectValue = JSON.parse(string);
return objectValue['mm'];
}
if this is a JSON String, at first of all you have to parse it to object liertal, then you can access the specified property you mentioned, so you can do like the following:
function parseJsonString(jsonString) {
// first parse it to object
var obj = JSON.parse(jsonString);
// now access your object property/key
var id = obj.insertedId;
}
If your doing it on mongodb shell or Robo3T then, the line of code would be:
db.collection_name.find({},{insertedId:1})
This is related to projection. 1 represents you want to display it as your output.
In your case as you want only the value of your object id to get displayed, you have to use .valueOf() ; that is ObjectId().valueOf().
-> insertedId: new ObjectId("612d9d08db9c20f031033478")
-> ObjectId("612d9d08db9c20f031033478").valueOf()
->
-> 612d9d08db9c20f031033478
Your can refer this : https://docs.mongodb.com/manual/reference/method/ObjectId.valueOf/ site for your reference.
So you can use this .valueOf() in your code and get the id saved in the document

How to give ID to a nested tabulator

I have a nested tabulator which I created in the following manner :
var Col= row.getCell("column").getElement();
var SubTd = document.createElement("td");
Col.appendChild(SubTd);
var subTable = new Tabulator(SubTd, {
data:row.getData().Xpaths,
columns:[{field:"Value",editor: true}]
})
I want to give an ID to 'subTable'. How should I do it? I read the documentation but can't find.
I am using Version 4.1.
You are creating a standard DOM node with the line:
var SubTd = document.createElement("td");
So to set the id you use the id property on the node:
SubTd.id = "whatever-id-you-want-to-use";
Though it would generally be considered bad practice to do this if you are adding a sub table for each row in the table as id's should be unique on the page and should not be duplicated.
If you want to do this for styling purposes you would be better of doing this in a class:
SubTd.classList.add("your-style");

What type of GUID on Mongoose

Currently, I used MongoVUE to import from current SQL Server database but all PK with uniqueidentifier were converted to something like "Binary - 3:UuidLegacy
My question is how do is create schema for this structure on Mongoose? I can't see Guid/UUID datatype on Mongoose docs http://mongoosejs.com/docs/api.html#schema_Schema.Types
And for more, I get issue when query with ValidationID something like
db.Validations.find({ValidationID: '1389AB5E-56BD-46FD-9A8A-258C7BDE4251'});
It returns nothing although this Guid is exactly same with SQL Server record.
Thanks.
MongoVUE is obscuring things a bit here, but in a nice way that makes it easier to read. Here's what your example ValidationID of '1389AB5E-56BD-46FD-9A8A-258C7BDE4251' actually looks like - it's type 3 BinData:
{"ValidationID" : BinData(3,"E4mrXla9Rv2aiiWMe95CUQ==")}
The viewer is converting that to a more readable format for you. It's doing that by converting to hex and adding dashes. For proof:
> var bar = BinData(3,"E4mrXla9Rv2aiiWMe95CUQ==")
> bar.hex()
1389ab5e56bd46fd9a8a258c7bde4251
If you want to find that ID, then strip the dashes and pass that into the find as follows (I inserted a sample doc):
> db.foo.find({ValidationID: UUID('1389AB5E56BD46FD9A8A258C7BDE4251')})
{ "_id" : ObjectId("544fd7ddbb4f50c77c61f367"), "ValidationID" : BinData(3,"E4mrXla9Rv2aiiWMe95CUQ==") }
I don't have mongoose set up to test, but have done the leg work in another answer similar to this in terms of converting in javascript.
This drove me crazy for several hours, as a solution I ended up having to install
npm install mongodb --save
npm install slugid --save
and code it as follows
var mongo = require('mongodb');
var slugid = require('slugid');
...
var guidb64 = slugid.encode(guid); // guid is something like '8440d561-1127-4fd8-aca9-54de19465d0b'
guidb64 = guidb64.replace(/_/g, '/'); // for whatever reason slug uses '_' instead of '/' I have in db
guidb64 += '=='; // adding missing trailing '==' I have in db
var GUID = new mongo.Binary(new Buffer(guidb64, 'base64'), 3);
var query = MySchemaType.findOne({ Guid: GUID });
query.exec(function(err, entity) {
// process
})

Missing FlashVars in Flash Professional CS5 and swfobject?

I have a Flash Professional CS5 movie which I'm trying to pass a parameter with swfobject. The problem is that movieclip's flashvar variables (under loaderInfo.parameters) is null.
Here is the swfobject code:
function loadSetupBar(connectId)
{
// add the setup bar to the DOM using swfobject
swfobject.embedSWF("{{setupBarSwf}}",
"swf-setup-bar",
{{gameWidth}}, $("#top-bar").height(),
"10.0.0", "{{installSwf}}",
{connectionId : connectId },
{
allowFullScreen : true,
wmode : 'opaque',
allowscriptaccess: "always"
},
{name:"swf-setup-bar"}
);
}
According to the swfobject documentation, everything seems to be ok.
Here's the corresponding code inside the FLA (A MovieClip with its own AS3 class):
var params : Object = root.loaderInfo.parameters;
var connectionId : String = params.connectionId;
if ( !params.hasOwnProperty('connectionId') )
// this line is always printed.
trace("[SetupBar-Error] loaderInfo parameters missing property 'connectionId'")
I'm not sure about what else to do.
Thanks.
EDIT: Here is a list of things I've tried that have failed:
casted root.loaderInfo to class LoaderInfo ( i.e. LoaderInfo(this.root.loaderInfo) )
passing a String literal in swfobject.embedSWF instead of param connectId
(i.e. {connectionID : 'myTestValue'})
There's a problem with the TLF TEXT control, when you add it to the stage the flashvars begins not working . just don't use it and your flashvars will work fine . i've faced the same problem and i got it solved by not using TLF TEXT control.
I hope i helped .
Best Regards
Try this:
var params:Object = LoaderInfo(this.root.loaderInfo).parameters;
var connectionID:String = params.connectionId;

Resources