Question Status

Verified
Michael_Land asked a question on 30 Jan 2013 5:49 AM

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

Reply
Suggested Answer
Joris de Gruyter responded on 30 Jan 2013 6:56 AM

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

Reply
Michael_Land responded on 31 Jan 2013 4:12 AM

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

Reply
Suggested Answer
Joris de Gruyter responded on 31 Jan 2013 8:39 AM

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.

Reply
Michael_Land responded on 31 Jan 2013 8:47 AM

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

Reply
Suggested Answer
Amir Nazim responded on 1 Feb 2013 6:16 AM

check this link

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

Reply
Michael_Land responded on 5 Feb 2013 4:45 AM

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

Reply
Michael_Land responded on 5 Feb 2013 5:37 AM

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

Reply
Suggested Answer
Joris de Gruyter responded on 5 Feb 2013 7:58 AM

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.

Reply
Michael_Land responded on 5 Feb 2013 8:35 AM

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

Reply
Suggested Answer
Joris de Gruyter responded on 5 Feb 2013 9:29 AM

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?

Reply
Michael_Land responded on 5 Feb 2013 11:38 AM

Hello,

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

I can't use in this case AIF.

Reply
Suggested Answer
Joris de Gruyter responded on 5 Feb 2013 12:37 PM

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

Reply
Michael_Land responded on 6 Feb 2013 4:45 AM

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

Reply
Verified Answer
Joris de Gruyter responded on 6 Feb 2013 7:53 AM

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.

Reply
Verified Answer
Joris de Gruyter responded on 6 Feb 2013 7:53 AM

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.

Reply
Suggested Answer
Joris de Gruyter responded on 30 Jan 2013 6:56 AM

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

Reply
Suggested Answer
Joris de Gruyter responded on 31 Jan 2013 8:39 AM

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.

Reply
Suggested Answer
Amir Nazim responded on 1 Feb 2013 6:16 AM

check this link

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

Reply
Suggested Answer
Joris de Gruyter responded on 5 Feb 2013 7:58 AM

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.

Reply
Suggested Answer
Joris de Gruyter responded on 5 Feb 2013 9:29 AM

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?

Reply
Suggested Answer
Joris de Gruyter responded on 5 Feb 2013 12:37 PM

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

Reply