Author Topic: xpath contains & starts-with method not recognized with JScript  (Read 2868 times)

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1370
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Hi,

I have a script that updates elements in EA from an input XML file.
I loaded the XML content using a "MSXML2.DOMDocument" activex in JScript and I need to loop through nodes which name attribute starts with "test".

I tried the following XPath expressions (tested ok with Notepad++ XPath Eval):
  • * var nodeList = xmlDOM.documentElement.selectNodes("//MyElement[contains(@name,'test')]");
  • * var nodeList = xmlDOM.documentElement.selectNodes("//MyElement[starts-with(@name,'test')]");
-> both return an "unknown method" error when executing the script

note: the following works ok in EA to fetch indivual entries.

var nodeList = xmlDOM.documentElement.selectNodes("//MyElement[@name='test1']");
var nodeList = xmlDOM.documentElement.selectNodes("//MyElement[@name='test2']");
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: xpath contains & starts-with method not recognized with JScript
« Reply #1 on: August 30, 2019, 07:09:40 pm »
Have you tried with CreateObject("MSXML2.DOMDocument.6.0")

I believe the MSXML2.DOMDocument is an older version of the same library.

Geert

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1370
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Re: xpath contains & starts-with method not recognized with JScript
« Reply #2 on: August 30, 2019, 07:39:39 pm »
It works!  ;D

Many thanks Geert
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com