Closed geoHeil closed 8 years ago
It seems you ran the command cxdd
instead of cxsd
.
Strange. But I definitely ran:
npm run cxdd someAwesomeSchema.xsd
and just confirmed that the issue persists.
You should instead run:
npm run cxsd someAwesomeSchema.xsd
And if your package.json
has a script cxdd
it should also be called cxsd
.
Sorry for the strange copy / paste error but in the terminal and now confirmed again it reads
npm run cxsd someAwesomeSchema.xsd
but when I format this as code the s
is replaced with a d
like npm run cxdd someAwesomeSchema.xsd
I did confirm that the package.json does not contain cxdd. The error still persists.
npm
gave a really strange error message there but the actual reason seems to be that cxsd
wants a remote URL address as a parameter, so you could put your .xsd
file online somewhere or try the following commands in the terminal (in the directory where you're running the npm commands):
sudo cp someAwesomeSchema.xsd /Library/WebServer/Documents/
sudo apachectl start
rm -rf cache && npm run cxsd http://localhost/someAwesomeSchema.xsd
That should set up a local web server providing the file. You can stop it with sudo apachectl stop
afterwards. The rm -rf cache
command is necessary to reload the .xsd
file if you change it.
cxsd
also wants the .xsd
file to have a target namespace, so it could contain:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsd:schema version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" vc:minVersion="1.1"
targetNamespace="http://some/awesome/schema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning">
<xsd:element name="myElem" type="myElem"/>
<xsd:complexType name="myElem">
<xsd:sequence>
<xsd:element name="geburtsdatum" type="xsd:date" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
This worked for me and produced the following TypeScript definitions under xmlns/some/awesome/schema.d.ts
:
import * as Primitive from '../../xml-primitives';
// Source files:
// http://localhost/someAwesomeSchema.xsd
interface BaseType {
_exists: boolean;
_namespace: string;
}
interface _myElem extends BaseType {
geburtsdatum?: Date;
}
export interface myElem extends _myElem { constructor: { new(): myElem }; }
export var myElem: { new(): myElem };
export interface document extends BaseType {
myElem: myElem;
}
export var document: document;
npm run cxdd https://gist.githubusercontent.com/geoHeil/865af42ddfeb2707150cb5ef05a7b3e5/raw/5adbca31cc3844e2184121580e19b8658d3e66dc/gistfile1.txt
leads to a:
[TypeError: Cannot read property 'getScope' of undefined]
What did you do different?
Add a targetNamespace="http://some/awesome/schema"
attribute inside the opening <xs:schema>
tag.
Later I'll probably fix the error message and add a command line parameter to specify the namespace if it's missing from the .xsd
.
Thanks for the tip. Finally this works. for https://gist.githubusercontent.com/geoHeil/865af42ddfeb2707150cb5ef05a7b3e5/raw/abdd0ad0ac9f93450e4ef41a5b9d20e13dee2cea/someAwesomeSchema.xsd
Trying to parse the following xsd (which validates fine) results in a strange error. --> the example of
npm run cxsd http://schemas.opengis.net/wfs/1.1.0/wfs.xsd
works just fine.Here the xsd:
here the error: