1
0
-1

Hello Everyone,

I'm currently working on a project which requires reading in XJMF and XJDF messages in C#. I was able to find some useful tools like the XML Schema Definition Tool provided by Microsoft.  This tool is supposed to be able to generate the class definitions when given an xsd file. However, after running through the generator and sending an XJMF signal message I am finding that the object created has the hierarchy of a regular XML object and not an XJMF message object. Sending an XJDF message creates an XJDF object with the expected XJDF hierarchy as expected.  I'm not sure if this is intended behavior or not; or if the xsd file potentially may have a mistake somewhere.

Steps to reproduce:
1. Download latest .xsd file.
2. Open 'Developer Command Prompt for Visual Studio 2017'
3. Type "xsd.exe {path to .xsd file} /c" (/c is short for generating classes).
4. Create new c# project and add generated .cs class file to project.
a. To add .cs file, simply right click the project -> Add -> Existing Item -> navigate and select generated .cs file
5. Add 'using' statements for System.Xml and System.Xml.Serialization.
6. Add XJMF .xml files to debug working directory.
7. Paste code for reading and deserializing xml data.
var reader1 = new XmlTextReader("xjmfFromCip4.xml");
XmlSerializer serializer1 = new XmlSerializer(typeof(XJMF));
var XJMFtest = (XJMF)serializer1.Deserialize(reader1);

Please let me know if you have any issues reproducing this or would like a sample project sent instead. Additionally let me know if you have any questions or answers as to why this behaves this way. If this is the intended behavior please let me know as well.

Thank You,
Satoshi

    CommentAdd your comment...

    2 answers

    1.  
      3
      2
      1

      Hi satoshi yuki,

      the images helped a lot to understand your issue.

      I traced your issue to a bug in our schema and filed it: JDF-537 - Abstract Elements reference concrete ComplexTypes WG Approve

      I already implemented a fix to the schema that is waiting to be merged: https://bitbucket.cip4.org/projects/SCHEMA/repos/xjdf-schema/browse/xjdf.xsd?at=refs%2Fheads%2FJDF-537

      Please check if your issue is solved by these changes and feel free to give feedback in JDF-537 - Abstract Elements reference concrete ComplexTypes WG Approve .

      Best regards,
      Michel

      1. satoshi yuki

        Hi Michel Hartmann,

        Thank you for the quick turn around and response.  Unfortunately the issue still seems to exist even with these changes.  I tried testing on both the class generator you provided as well as the one provided by Microsoft. Interestingly they produce very different class files but the results of the parse seem to be the same which is comforting.

        The behavior does not seem to have changed and XJDF still parses and builds an object as expected but the XJMF object still has the xml.xmlElement hierarchy.

        Regards,

        Satoshi

      2. Michel Hartmann

        Hi satoshi yuki,

        if the schema change did not help I have no further idea how to assist you.

        The last thing I could think of was updating my sample (https://bitbucket.cip4.org/users/mlhartmann/repos/xjdflibcsharp/diff/xJdfLibCSharp/generated/xjdf.cs?until=95ffb570b15fe9a31134faa6a1d5c1fa169aa642). The code in that repository produces the following structure:

        I suppose that is what you want to achive. Correct?

        Best regards,
        Michel

      3. satoshi yuki

        Hi Michel Hartmann,

        Thanks again for double checking and feedback.  Turns out the Microsoft provided xsd.exe does not generate the class file I was hoping for but the project you provided did.  I think I just placed the .xsd in the wrong directory on accident and didn't realize since I was jumping around different folders when I was testing your solution.
        Anyways, this did indeed resolve my problem and it seems to function as expected as long as I use the generator you provided.

        Thanks again for your help and support!
        Satoshi

      CommentAdd your comment...
    2.  
      2
      1
      0

      Hi Satoshi,

      I maintain a java library (https://bitbucket.cip4.org/projects/LIB/repos/xjdflib/browse) that is build around java classes that are generated from the XJDF-schema. Although it is a different programming language it might help you to overcome your issue.

      The relevant part can be found here: https://bitbucket.cip4.org/projects/LIB/repos/xjdflib/browse/build.gradle#78

      To give you some background to my approach:
      The equivalent to "XML Schema Definition Tool" in java is called "xjc" and reads the XSD and generates the java source code. The referenced file "binding.xjb" contains some configuration to bind certain XSD-types to java classes. In order to see the generation at work, you need a JDK. Then it should be sufficient to execute "./gradlew test" in the project root. This will geenrate the code, build everything and run the test suite.

      Hopefully I will find some time in the next days to reproduce your steps in order to give you some hints. But as time is quite rare, I can't promisse anything.

      If you find a solution in the meantime, I'm happy to hear about it. Perhaps we could even publish the solution as an open source project for other C# developers.

      Greetings from Germany,
      Michel

      1. Michel Hartmann

        Surprisingly enough, I actually found a little time to put somethin together. Having a Mac I could not use the xsd.exe but went for https://github.com/mganss/XmlSchemaClassGenerator.

        The resulting code seems to be able to parse the xjmf without problems: https://bitbucket.cip4.org/users/mlhartmann/repos/xjdflibcsharp/browse

        Hope this helps you to get XJDF running.

      2. satoshi yuki

        Hi Michel, 

        I haven't had a chance to look at your solution yet but will definitely get to it.  Thanks for taking the time to come up with such a thorough response and solution.  Hopefully I am able to get through it no problems.  I will let you know if I have any issues but I might not get a chance to look at it until some time next week.


        Thanks again,

        Satoshi

      3. satoshi yuki

        Hello again Michel,

        I was able to build your project and generate a class file.  Unfortunately I don't believe the XJMF is parsed like I expect.  I'm not sure if you're getting the same results but I've attached 2 images of the XJMF hierarchy and 1 image of the XJDF hierarchy.  I probably was not clear on what exactly my issue was so I am posting pictures here to clarify what I am seeing.  I wanted to point out that XJMF looks like the standard XML hierarchy seen here https://docs.microsoft.com/en-us/dotnet/api/system.xml.xmlelement?view=netframework-4.7.2  Below are two screenshots of XJMF followed by a screenshot of XJDF.  The XJDF has the hierarchy I would expect, but the XJMF looks just like a standard XML.XMLElement which is not what I expect from generating an XJMF Class.  Is this to be expected or not?  I could potentially be misunderstanding what the generated class should look like.  

        Again, if this is the intended behavior I guess this post can be deleted, but if this is the intended behavior it doesn't seem like it'd be very useful for my use case.

        Thanks again,

        Satoshi

      CommentAdd your comment...