Creating Class from xsd-file (AX 2012)

This question is answered

Hello,

Are there any tools/utility classes to create a class in runtime or with a tool from command prompt using xsd file?

I mean same kind of utility than xsd.exe in .NET.

Thanks,

Michael

Verified Answer
All Replies
  • Technically you could manipulate AOT TreeNode directly, but there is a class called "ClassBuild" which is easy to use.

  • Hello, I coudn't  find any samples how to create X++ class in code from XMLSchema (xsd) using ClassBuild.

    I didn't also find any tool like xsd.exe to generate X++ class from .xsd file.

    Are there any samples to do this or any tools available?

    Thanks,

    Michael

  • The tools you're asking for are not available to my knowledge. The ClassBuild class allows you to create a new class so that would be your starting point to implement the feature you need.

  • I found couple of ClassBuild examples but none of them had sample how to add member variables.

    My need is to create a quite big class containing lot's of member variables and methods.

    But I didn't find any samples how to do it. E,g. Interface of ClassBuild has changed so, that there were not AddMemberVariable anymore.

    So how to do this?

    Thanks,

    Michael

  • check this link

    www.doens.be/.../create-class-from-code

  • Hello again,

    Still struggling with this same problem.

    The XMLSchema that is used for creating that class is 1400 lines long ...

    Are there any possibilities to create Xml Document from XML Screma and then fill it and somehow serialize it to file...

    How you others have solve this kind of issue?

    There is a long XSD based message or class that should be created and then filled wih data that exits in software and then make it as a file?

    Br

    Michael

  • What else came to mind was that because we use SQL Server and it can support creating Tables from XMLSchemas... has anyone tried to solve this kind of issue using Database?

    Br

    Michael

  • I'm not entirely following your scenario. I thought you had class definitions in XML and wanted to automate the creation of those classes in X++. But now you're asking how to create the XML files, so I'm somewhat confused as to what you are trying to do exactly, and mostly why. If you still need to create the XMLs, then create the tool to import them... seems like a lot of work so the question is why. Alternatively, if you need to somehow generate code from outside of AX, consider generating an XPO file that can be imported into AX. The XPO format for classes is fairly simple to understand.

    Either way, there are tools out there to create XML instances out of schemas, some are online and free, others are tools you can purchase. If you have Microsoft Office including InfoPath you can try using InfoPath for this, but it may require some cleanup of the resulting XML.

  • Thanks for answering!

    So the clearified situation is this.

    a) I have a Invoice XSD which should be used to get a XML file that is compability with this invoice XSD.

    b) First  I should fill data from AX Database to a Class or XML Document which is compability  with XSD Schema above

    c) After filling data into Class or XML Document which is compability with XSD Schema I should write that into filesystem.

    That is the basic flow. Because XML Schema has so much variables, collections etc I can't do it with basic programming meaning going one by one with every variable.

    Is this any clearer? :)

    Br

    Michael

  • Have you considered dumping the AX invoice to a regular AX XML file, then using an XSLT to transform the XML into an XML your XSD can validate?

  • Hello,

    But how to dump invoice to regular AX XML file? That's a quite problem.

    I can't use in this case AIF.

  • AIF would be the easy choice, why is that not possible?

  • Thanks for answering!

    I thing I have understood same things wrong.

    Isn't it so that this MSDN tells how to export data into XML file?

    msdn.microsoft.com/.../bb530214(v=ax.50).aspx

    And my situation is that a button in Form will start the whole export chain.

    Now, when I have a own XMLSchema am I rigth that I must override some code in code that resides MSDN link above?

    But where and how should I modify code so that exported XMLfile would be consisten with my XMLSchema?

    Do I start to understand the whole process ? :) :)

    Michael

  • You can't modify the xml layout that AX generates, but you can add an XSLT transformation. This allows you to transform the AX xml layout into the layout you need.