Author Topic: XML elementNode.appendChild(childNode) - JAVASCRIPT  (Read 12560 times)

daniel.levy

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
XML elementNode.appendChild(childNode) - JAVASCRIPT
« 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 :
  • which JavaScript and wich version is built-in in EA13 ? (Spider Monkey ??)
  • where I can find the references and functions of this JavaScript ?
  • How it is possible to append a ChildNode to an Element Node in a script (JavaScript) written inside EA13 ?

Best Regards,

Daniel
« Last Edit: June 14, 2017, 12:40:06 am by daniel.levy »
D. LEVY

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: XML elementNode.appendChild(childNode)
« Reply #1 on: June 13, 2017, 11:05:56 pm »
Looks more like a question you should ask the Java guys on StackOverflow.

q.

daniel.levy

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
« Reply #2 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
D. LEVY

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: XML elementNode.appendChild(childNode)
« Reply #3 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/

q.

daniel.levy

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
« Reply #4 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
D. LEVY

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
« Reply #5 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.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13402
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
« Reply #6 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

daniel.levy

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
« Reply #7 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 : 
  • I can't debug anymore VBScripts or JScripts since we have installed Windows 10 Pro and Enterprise Architect 13.0.1310. I can only debug JavaScript inside EA13. I tried to install the Microsoft Script Debugger (scd10en.exe) as it was used to work with Windows 7 Pro and EA12 but I couldn't manage to debug JScripts and VBScripts inside EA13.
  • As you know, Microsoft doesn't offer his Microsoft Script Debugger anymore. I can't afford to buy something like Microsoft Visual Studio just for getting their Microsoft Script Debugger.
  • Sparx recommanded me to develop JavaScript scripts inside EA13 to be sure that I would be able to debug.
  • A lot of EA functions as for instance Repository.SQLQuery(aQuery) returns an XML flow. So I don't know how I'll be able to read and manipulate XML results using JavaScript inside EA13 if I can't manipulate a XML DOM.
  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

D. LEVY

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13402
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
« Reply #8 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

daniel.levy

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
« Reply #9 on: June 16, 2017, 10:37:17 pm »
Hi Geert, 
No, it is not the problem.
  • 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" );
 
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 :
  • loadXML() ---------------------> xmlDOM.loadXML(SEARCH_SPECIFICATION);
  • createElement() --------------> row = pXmlDOM.createElement("Row");
 
But the problem begins now if you have to handle your XML DOM :
  • parentNode.appendChild(childNode); will operate seamlessly in JScript. That will append an XML childNode to your parentNode.
  • parentNode.appendChild(childNode); won't work in JavaScript because this function doesn't exist. And I can't find an equivalent function or how to do it in SpiderMonkey JavaScript 1.8.
 
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 
D. LEVY

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13402
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
« Reply #10 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

George

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
« Reply #11 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

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
« Reply #12 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.

VKN

  • EA User
  • **
  • Posts: 187
  • Karma: +9/-1
    • View Profile
Re: XML elementNode.appendChild(childNode) - JAVASCRIPT
« Reply #13 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
« Last Edit: August 04, 2017, 11:02:22 am by VKN »