Importing complex network of schemas

  • David Meyer

    David Meyer - 2013-02-07

    I have a set of schemas that have multiple circular references to each other. There are various categories that these schemas fall under, so each set is in a sub-directory of the folder holding a master schema. When I import the set of schemas I kept getting file location errors, and it seems that when pyxb requires all file references to be from the master directory. Is this correct?
    For example, say I have a schema SpecificTypes.xsd located in the folder Specific that imports BasicTypes.xsd that is in the master directory. I have to write inside SpecificTypes.xsd

    <xs:import schemaLocation="BasicTypes.xsd"/>

    Which I would have thought that I needed the "./" in front of BasicTypes to tell windows that I want to access the parent folder.

    Now lets say I have another schema in a different folder. For example, I have a folder called capability and inside it has a document called capability.xsd that needs to import SpecificTypes.xsd. I have to call it what I would think is a strange manner:

    <xs:import schemaLocation="Specific/SpecificTypes.xsd"/>

    This is strange because it looks like Specific would be a sub-directory within capability, but if I include the "./" I get a file error.

    I wouldn't complain too loudly if this was the only problem. Once I make all of these changes though, the python scripts that are generated contain poorly structured import commands. In the case of there is an import command in python that reads:

    import Specific/SpecificTypes

    which just creates a headache for me. So the first few times I ran the program I just fixed all references by hand, changing the import line to

    from Specific import SpecificTypes

    and changed all references to Specific/SpecificTypes to SpecificTypes. Can I do something different when I call pyxb to fix this error?

  • Peter A. Bigot

    Peter A. Bigot - 2013-02-07

    Have you reviewed the material in the user manual at:

    Without seeing exactly what you have I can't tell you how to solve it, but in general the process requires invoking pyxb on all the schema that have interconnections at once.  If you have one set with mutual dependencies, and a second set that depends on the first, then it's best to convert the first all at once and use an archive, which the second set then reads.

    You can control where PyXB looks for the schema with these options:

    You can control the names of the modules (including module paths) that PyXB generates with these options:

    Your best bet is to try various things, possibly with a reduced set of toy schema that only have a few elements, until you understand how it all works.

    If you are actually getting commands to:

    import Specific/SpecificTypes

    instead of

    import Specific.SpecificTypes

    that shouldn't happen and must be from the way you invoke pyxbgen (e.g., if you specified -m Specific/SpecificTypes instead of -m Specific.SpecificTypes).  If you're getting the second version but stylistically prefer the "from Specific import SpecificTypes" format in the generated code, that's not something PyXB supports.

  • David Meyer

    David Meyer - 2013-02-07

    Ohh, get thanks. I generate all of the python at once with a ridiculously long pyxbgen call in cmd. I will change the way I use the generate command and see if all of my pain goes away.

  • David Meyer

    David Meyer - 2013-02-07

    The import commands in python work perfectly now and I don't have to go through by hand.

    I have read through the section about namespaces and importing other schema, I was just surprised that JAXB can import the schemas without making this modification. The original capability.xsd contained this line for the import command :

    <xs:import schemaLocation="../Specific/SpecificTypes.xsd"/>

    However, I received an error that there was no file and the problem was that it looked one level too high and I would get a file does not exist error at:


    When the file should have been at C:\blahblah\master\SpecificTypes because master was one directory up. If I make it one dot instead of two there is the same problem. However, changing capability.xsd to

    <xs:import schemaLocation="Specific/SpecificTypes.xsd"/>

    Works, even though I would have thought that this would point to:


    and not


    The directories are laid out as follows:

    C:\blahblah\master -> contains the master.xsd file that imports everything else and BasicTypes.xsd which is a supporting document

    C:\blahblah\master\Specific -> contains the file SpecificType.xsd (and others but that isn't important)

    C:\blahblah\master\capability -> contains the file capability.xsd (and others)

    I am trying to reference SpecificType.xsd from capability.xsd and pyxb requires me to make all references for the import commands in the xml from the master directory, even if the file doing the import is in a sub-folder. Is this what is supposed to happen?

  • Peter A. Bigot

    Peter A. Bigot - 2013-02-07

    No, the schema location is supposed to be normalized relative to the location of the importing schema, assuming the root import location was specified relative to the -schema-root value.  There have historically been problems under Windows because XML schema use forward slash as a path separator while Windows uses backslash, and normalization between these systems was not reliable.


Log in to post a comment.