开发者

How to generate Objective C class files from XML schema?

I have an XML schema 开发者_JS百科that defines my data model. I would now like to have Objective C source files generated from the XML schema. Does anyone know how to accomplish this?


Take a look at this Stack Overflow question on XML serialization, which mentions a project along these lines.


Without knowing the details my immediate thought would be to probably use xslt for this. e.g. if you had 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,e.g.

<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>

...

Though if the logic on the generation is more complex I would probably go down the road of importing the xml into an object model and programmatically process that, possibly using a template engine such as Velocity, as while it is possible complex logic in xslt is a pain.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜