Book a Demo

Author Topic: JScript Error when using GenerateXSD  (Read 5404 times)

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
JScript Error when using GenerateXSD
« on: November 05, 2016, 03:59:07 am »
Hi All

I am developing a script and using JScript (this the choice of the client for whom I am developing the script).

This is my code

   projectInterface.GenerateXSD(thePackage.PackageGUID, "C\EA-Projects\Generated1.xsd", "Unicode (UTF-8)", "GenGlobalElement=1");
   Session.Prompt("Error " + projectInterface.GetLastError(), promptOK);

Upon execution I receive an Error from EA informing me that Access is Denied. I certainly have write access to the file specified.
The result of the GetLastError is

Please specify output file name.

Which clearly I have.

Using the same file path and options, via invoking Generate XML Schema from the Project Browser package works just fine.

I get the same error whether the filename is hardcoded or accepted from Save As dialog, and no matter what the file path is.

The PackageGUID is definitely the root package of an XSD schema.

Ah just noticed the User Guide specifies that the PackgeGUID must be in XML format, but does not state what that should look like.
I am simply passing the GUID as a string, so this maybe the cause.

What should the PackageGUID string look like in XML format?

Any ideas?

Cheers

Phil
Models are great!
Correct models are even greater!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: JScript Error when using GenerateXSD
« Reply #1 on: November 05, 2016, 06:06:41 am »
I guess it should be " "C:\EA-Projects\Generated" rather than " "C\EA-Projects\Generated"

q.

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
Re: JScript Error when using GenerateXSD
« Reply #2 on: November 05, 2016, 07:27:18 am »
Definite red-face time  :-[ Should have spotted the missing : after C

Added the missing : same result

Access Denied

However, by converting the string GUID to XML using GUIDtoMXL, I get rid of the access denied, but it still does not work  >:(

This time I get

Unspecified error

with GetLastError returning a null string. So no help or clue there.

Cheers

Phil

Models are great!
Correct models are even greater!

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
Re: JScript Error when using GenerateXSD
« Reply #3 on: November 05, 2016, 08:22:54 am »
Fixed it!

The problem was with the XML encoding string

It should be utf-8 and not Unicode (UTF-8)

What confused me was that using the Code Generation from the Project Browser, the dialog lists Unicode (UTF-8), hence I used that in the script.

However, upon examining a generated XSD schema, I found t should be utf-8, put that in the script and it worked!

My correct call is

projectInterface.GenerateXSD(projectInterface.GUIDtoXML(thePackage.PackageGUID), fileName, "utf-8", "GenGlobalElement=0");

where filename has been obtained as :

var fileName = projectInterface.GetFileNameDialog("", "XML Schema Files (*.xsd)|*.xsd", 1, 2, "C:\\EA-Projects\\", 1);

Cheers
Phil
Models are great!
Correct models are even greater!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: JScript Error when using GenerateXSD
« Reply #4 on: November 05, 2016, 08:34:15 am »
I have that kind of error (the missing colon) all times. Usually I get the idea after a break or a good sleep :-) Thanks for posting the other caveats. I also got this Unspecified Error but stopped further tests after spotting the colon.

q.