Convert XSD to TypeScript
Asked Answered
I

3

7

I found this tool. CXSD

On their documentation: cxsd is a streaming XSD parser and XML parser generator for Node.js and (optionally but highly recommended) TypeScript. This is exactly what I need, so I follow their documentation and start to execute commands.

I have a problem when I try to execute this command: npm run cxsd file:///C:/XSDtoTypeScript/Flexinova.RBF.LI.V1.xsd

Unhandled rejection Error: Invalid URI "file:///C:/XSDtoTypeScript/Flexinova.RBF.LI.V1.xsd"

But when I try to open this from a browser, it opens normally. I don't know why URI is invalid? Does anyone know?

Ironing answered 28/8, 2018 at 10:4 Comment(0)
I
9

• Run command: npm install http-server -g

• Open Node.js command prompt as administrator and raise your file on localhost using following command: http-server C:\XSDtoTypeScript

• Now try to open your xsd which is in this folder. Example: http://localhost:8080/Flexinova.RBF.LI.V1.xsd

Now use the command: npm run cxsd http://localhost:8080/Flexinova.RBF.LI.V1.xsd You are done 😊

Ironing answered 28/8, 2018 at 12:27 Comment(0)
C
1

I got it working using these steps:

  1. Create a package.json
{
  "scripts": {
    "dev": "http-server",
    "convert": "cxsd"
  },
  "dependencies": {
    "cxsd": "^0.1.1",
    "http-server": "^14.1.1"
  }
}
  1. Running a server to share local files via http:
nvm install v12
npm run dev
  1. Run the convertor in a separate tab:
nvm use v12
npm run convert http://localhost:8080/file.xsd
Cilo answered 19/1, 2024 at 5:48 Comment(0)
K
0

How to run in 2024:

The cxsd package only works with Node.js 12.

But it looks like it works with Bun, so you can simply call it with bunx: bunx cxsd http://your-xsd-file.xsd

Note that you may need to upload your XSD file to some https server (see previous response on how to make a quick http server) on your localhost.

Karoline answered 17/1, 2024 at 11:1 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.