Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: daniel.levy on June 13, 2017, 10:30:14 pm

Title: XML elementNode.appendChild(childNode) - JAVASCRIPT
Post by: daniel.levy on June 13, 2017, 10:30:14 pm
Hi everybody  :),

I'm trying to write a JavaScript in EA;13.0.1310 (Windows 10 Pro).

I need to append a ChildNode to an ElementNode (XML) :

elementNode.appendChild(childNode);

this works seamlessly with JScript, but not at all with JavaScript.

Does anyone know :

Best Regards,

Daniel
Title: Re: XML elementNode.appendChild(childNode)
Post by: qwerty on June 13, 2017, 11:05:56 pm
Looks more like a question you should ask the Java guys on StackOverflow.

q.
Title: Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
Post by: daniel.levy on June 14, 2017, 12:02:51 am
Hi qwerty,

I'm sorry but I'm french and I'm not sure I have quite understood your answer.

I am not asking about Java but JavaScript in EA 13.

I've got a function in my script (JavaScript) where pRow is an XML Node from the DOM pXmlDOM :

<code>
function AddField(pXmlDOM, pRow, pNomDuChamp, pValeurDuChamp) {
   
    var fieldNode = pXmlDOM.createElement("Field");
   
    fieldNode.setAttribute("name", pNomDuChamp);
   
    fieldNode.setAttribute("value", pValeurDuChamp);
   
/* ************************************* */
/* DOES NOT WORK !!!! */
/* ************************************* */
    pRow.appendChild(fieldNode);

}
</code>

EA says that  appendChild(...) is not a function for the object XML Node pRow.

This operates seamlessly with JScript, but not with JavaScript.

So, do you know how I could figure out this issue in JavaScript ?

Thanks,

Daniel
Title: Re: XML elementNode.appendChild(childNode)
Post by: qwerty on June 14, 2017, 12:06:15 am
You are not asking for something EA specific, but something about Java/Script and DOM. You should place your question at https://stackoverflow.com/ (https://stackoverflow.com/)

q.
Title: Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
Post by: daniel.levy on June 14, 2017, 12:32:53 am
Hi qwerty,
thank you for your pointful answer but I'm not quite sure.

If you take a look at JavaScript documentation (here for instance : https://developer.mozilla.org/fr/docs/Web/API/Node/appendChild), you 'll see that appendChild(...) exists. So, I'm affraid that the guys at https://stackoverflow.com/ will answser me that my code is correct in JavaScript.

It looks like the issue comes from JavaScript built-in EA13.0.1310. That's why I was asking about the type and the version of JavaScript builted-in EA 13. I saw that it could be spiderMonkey JavaScript on this forum but I couldn't find any version or where to find the documentation.

I would like to verify if appendChild(...)  exists for JavaScript builted-in EA13.

In my script, I'm listing the whole connectors (EA.Connector) appearing on a diagram.

Maybe it would be useful if I could send you my scripts (both JScript and JavaScript) ?

You could see that my script is good when written in JScript. The only problem remains in JavaScript.

Maybe you or someone else have done such that kind of script in JavaScript ? In fact, I'm looking for examples showing how to manipulate XML DOM inside scripts (JavaScript) in EA 13.

Best regards,

Daniel
Title: Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
Post by: qwerty on June 14, 2017, 04:47:05 am
If none of the supporters picks this up the next days, you might eventually send a support request to Sparx.

q.
Title: Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
Post by: Geert Bellekens on June 16, 2017, 05:51:45 pm
If none of the supporters picks this up the next days, you might eventually send a support request to Sparx.

q.

If you search deep enough in this forum you should be able to find a reference to which version exact version of Javascript is supported.
But I'm not even sure if it's a Javascript issue or an issue with the XML library you are using (or is that native Javascript?)

In VBScript you have to use a .Net xml library to do these type of things.

Geert
Title: Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
Post by: daniel.levy on June 16, 2017, 09:18:01 pm
Hi Geert, 
It's good to hear from you  :). 
I looked deep inside this forum but I never could find how to manipulate an XML DOM with this JavaScript builted-in EA13.0.1310 (SpiderMonkey JavaScript 1.8 ). 
I posted my question on StackOverflow (here : https://stackoverflow.com/questions/44570789/handling-xml-dom-in-spidermonkey-javascript-1-8-function-appendchildchildnode) and it seems that SpiderMonkey JavaScript 1.8 doesn't have the libraries to manipulate XML DOM ... 
  This causes big problems because : 
  As you can see, in EAScriptLib, you 've got a JScript-XML library and a VBScript-XML library. But you don't have a JavaScript-XML Library. 
So I'm still wondering how I could add a JavaScript XML library inside EA13 so that I could use such functions as append(), appendChild(), ... My purpose is to be able to manipulate the results of EA functions using EA JavaScript. 
Best regards, 
Daniel

Title: Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
Post by: Geert Bellekens on June 16, 2017, 09:41:58 pm
Daniel,

As I understand it you should be able to use any .Net library that is known in your system from Jscript, VBScript or Javascript.
The only difference is the way to instantiate the XML DOM object.
In VBSscript you have to use CreateObject( "Microsoft.XMLDOM" ) but I believe there is a similar command for both Jscript as Javascript.

There is a  post on the forum here somewhere that explains the difference in syntax for the different scripting languages when instantiating external library objects.

Geert
Title: Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
Post by: daniel.levy on June 16, 2017, 10:37:17 pm
Hi Geert, 
No, it is not the problem.
 
The problem is now how to manipulate this DOM. There are commands than you can use in both langages (JScript and JavaScript either). For instance :
 
But the problem begins now if you have to handle your XML DOM :
 
So, the main problem is how to handle an XML DOM (retrieve a Node, append a Node, read a DOM, ...) inside EA13 with JavaScript as you are able to do with JScript or VBScript.
 
Best Regards,
 
Daniel 
Title: Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
Post by: Geert Bellekens on June 18, 2017, 02:21:46 pm
  • It's easy to instantiate a DOM in JScript inside EA13. For instance : xmlDOM = new ActiveXObject( "MSXML2.DOMDocument.6.0" );
  • It's also easy to instantiate a DOM in JavaScript inside EA13. for instance : xmlDOM = new COMObject( "MSXML2.DOMDocument" );

I'm still not convinced. You are instantiating a different type of object in both lines. Possibly (I don't know, check the documentation) MSXML2.DOMDocument doesn't have a "appendChild()" operation where MSXML2.DOMDocument.6.0 has.

I'm still pretty sure it's related to the DOM object you are using rather then the scripting language.

Geert
Title: Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
Post by: George on July 31, 2017, 08:47:02 pm
Hi Daniel and Geert,
did you manage to fix this problem?
I struggle with the same, I think.
In JavaScript:
------
var xmlDOM = new COMObject( "MSXML2.DOMDocument" );
...
var nodeList = xmlDOM.documentElement.selectNodes( nodePath );
error: xmlDOM.documentElement.selectNodes is not a function
------
In JScript it works, with appropriate DOM object creation - new ActiveXObject( "MSXML2.DOMDocument" )).
I tried both, "MSXML2.DOMDocument" and "MSXML2.DOMDocument.6.0", error is the same.
Best regards
Jiri
Title: Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
Post by: Aaron B on August 04, 2017, 10:19:03 am
Hi All,

This is a confirmed issue which is being investigated by our development team. Unfortunately the JavaScript engine used by EA currently fails to handle inherited methods for COM objects, which is what causes problems when trying to use MSXML objects to read/write xml. For example, appendChild() is not a function of IXMLDomElement, but is actually inherited from IXMLDOMNode.

We hope to fix this in a future build. No word yet regarding in which specific build this will be fixed.
Title: Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
Post by: VKN on August 04, 2017, 10:40:45 am
Does anyone know :
  • which JavaScript and wich version is built-in in EA13 ? (Spider Monkey ??)
SpiderMonkey 1.8