Creating XML from schema?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • A. W. Dunstan

    Creating XML from schema?

    I've got a schema file (four, actually - one includes the other three) and
    am trying to create a 'sample' XML file from it.

    I tried reading the .xsd files myself but the four of them combined add up
    to more than 4000 lines - more than enough to put me to sleep.

    I also tried some Java:

    SchemaFactory sf =
    SchemaFactory.n ewInstance(XMLC onstants.W3C_XM L_SCHEMA_NS_URI );
    Schema schema = sf.newSchema(ne w File("/path/to/main/schema/file.xsd"));
    DocumentBuilder Factory dbf = DocumentBuilder Factory.newInst ance();
    dbf.setSchema(s chema);
    dbf.setNamespac eAware(true);
    dbf.setValidati ng(true);
    dbf.setXInclude Aware(true);
    DocumentBuilder db = dbf.newDocument Builder();
    Document d = db.newDocument( );

    which compiles & runs without incident when run from the directory with the
    schema files, but produces an empty Document (zero child nodes).

    I'm working on getting a sample XML document from the folks I got the schema
    from, but that might take a while.

    I've looked around in NetBeans and IntelliJ but haven't seen anything that
    looks like it'll do what I want. They can both _validate_ an existing XML
    file, but that's what I'm trying to create.

    Is there a way to do this?

    I realize it might not be possible - some of the nodes might be 'choose
    exactly one of A or B', or 'if you have X you must also have Y but if not
    then you must have Z' and I'd then need some way of saying which option(s)
    to go with.

    I really don't care what values the text/numeric fields have; empty (or
    zero) would be fine - I can stuff 'realistic' data in afterward, once I've
    got the structure of the document spelled out.

    thanks!

    --
    Al Dunstan, Software Engineer
    OptiMetrics, Inc.
    3115 Professional Drive
    Ann Arbor, MI 48104-5131
  • Martin Honnen

    #2
    Re: Creating XML from schema?

    A. W. Dunstan wrote:
    I've got a schema file (four, actually - one includes the other three) and
    am trying to create a 'sample' XML file from it.
    >
    I tried reading the .xsd files myself but the four of them combined add up
    to more than 4000 lines - more than enough to put me to sleep.
    >
    I also tried some Java:
    I don't know of a Java solution.
    Here is an article about doing it with the .NET framework:



    --

    Martin Honnen

    Comment

    • A. W. Dunstan

      #3
      Re: Creating XML from schema?

      Found one! Eclipse did a decent job of it. Create a Java project, add the
      Schema files to the project, right click on the main schema file & select
      Generate->XML.

      It gives text fields a value equal to the name of the element itself:

      <SpecialNotatio n attrib="A">Spec ialNotation</SpecialNotation >

      even though many of them have additional restrictions placed on them -
      min/max length, allowed characters (all caps & limited punctuation in this
      case), select-from-enumerated-list, etc.

      But it gave me a decent structure to start out with; I can fill in valid
      values with an editor.


      --
      Al Dunstan, Software Engineer
      OptiMetrics, Inc.
      3115 Professional Drive
      Ann Arbor, MI 48104-5131

      Comment

      • J Leonard

        #4
        Re: Creating XML from schema?

        On Jul 7, 11:26 am, "A. W. Dunstan" <n...@spam.than kswrote:
        I've got a schema file (four, actually - one includes the other three) and
        am trying to create a 'sample' XML file from it.
        >
        I tried reading the .xsd files myself but the four of them combined add up
        to more than 4000 lines - more than enough to put me to sleep.
        >
        I also tried some Java:
        >
        SchemaFactory sf =
        SchemaFactory.n ewInstance(XMLC onstants.W3C_XM L_SCHEMA_NS_URI );
        Schema schema = sf.newSchema(ne w File("/path/to/main/schema/file.xsd"));
        DocumentBuilder Factory dbf = DocumentBuilder Factory.newInst ance();
        dbf.setSchema(s chema);
        dbf.setNamespac eAware(true);
        dbf.setValidati ng(true);
        dbf.setXInclude Aware(true);
        DocumentBuilder db = dbf.newDocument Builder();
        Document d = db.newDocument( );
        >
        which compiles & runs without incident when run from the directory with the
        schema files, but produces an empty Document (zero child nodes).
        >
        I'm working on getting a sample XML document from the folks I got the schema
        from, but that might take a while.
        >
        I've looked around in NetBeans and IntelliJ but haven't seen anything that
        looks like it'll do what I want. They can both _validate_ an existing XML
        file, but that's what I'm trying to create.
        >
        Is there a way to do this?
        >
        I realize it might not be possible - some of the nodes might be 'choose
        exactly one of A or B', or 'if you have X you must also have Y but if not
        then you must have Z' and I'd then need some way of saying which option(s)
        to go with.
        >
        I really don't care what values the text/numeric fields have; empty (or
        zero) would be fine - I can stuff 'realistic' data in afterward, once I've
        got the structure of the document spelled out.
        >
        thanks!
        >
        --
        Al Dunstan, Software Engineer
        OptiMetrics, Inc.
        3115 Professional Drive
        Ann Arbor, MI 48104-5131
        I don’t know if this is what you want but Eclipse does this very
        nicely.

        J Leonard

        Comment

        Working...