How to generate Objective-C class files from an XML schema?

I have an XML schema that defines my data model. Now I would like to have Objective-C source files created from an XML schema. Does anyone know how to do this?

+4
source share
2 answers

Take a look at this XML serialization stack overflow question that mentions the project in these lines.

+1
source

Without knowing the details, I immediately thought that it would probably use xslt for this. for example if you have something like (I appreciate

<element name="SomeEntity"> <attribute name="someAttr" type="integer" /> <complexType> <sequence> <element name="someOtherAttr" type="string" /> </sequence> </complexType> </entity> 

Create a bunch of templates to translate this, for example.

 <xsl:template match="element"> <xsl:apply-template select="." mode="header"/> <xsl:apply-template select="." mode="impl"/> </xsl:template> <xsl:template match="element" mode="header"> class <xsl:value-of select="@name"/> { public: <xsl:apply-template select="attribute" mode="header"/> <xsl:apply-template select="complexType/element" mode="header"/> </xsl:template> ... 

Although, if the generation logic is more complex, I would probably go along the path of importing xml into the object model and process it programmatically, possibly using a template engine such as Velocity, because although it is possible the complex logic in xslt is a pain.

0
source

Source: https://habr.com/ru/post/1305208/


All Articles