Issue with Generate from XML template

Issue with Generate from XML template

Old forum URL: forums.lhotka.net/forums/t/1708.aspx


wjcomeaux posted on Tuesday, November 07, 2006

The template that generates business objects from XML has an issue with Namespaces.

If you generate against the XML at the end of this message, and try to change the namespace on each object, only the first couple of namespaces get used. For instance, all my objects fall under EditableChild and ReadOnlyChildList. What should be an object under EditableRoot is placed under the EditableChild namespace (incorrectly).

I have verified that the proper templates are getting called as I have comments at the top of each template that outputs the template name so I know that the EditableRoot object is being generated against the correct template, but the namespace is incorrect.

In the template I have

//EditableRoot
<% if (objInfo.Namespace.Length > 0) { %>namespace <%= objInfo.Namespace %>

This only uses the correct namespace for the first and last objects in the XML file.

In the OutputSubTemplate function I am doing the following 

  subTemplate.SetProperty("ClassNamespace", _projectNamespace);
  subTemplate.SetProperty("Namespace", _projectNamespace);

and I have verified that the namespace is correct at this point. It's when the code is actually generated that the objInfo.Namespace does not contain the correct value.

Thanks, Will

- <Objects>
- <Object Access="public" Type="EditableChild" NameSpace="EditableChild" Name="Building">
- <Properties>
- <Property Name="_ID" DbColumnName="_ID" Description="" Type="int" DataType="Int32" NativeType="int" SystemType="System.Int32" IsPrimaryKey="true" IsIdentity="true">
- <ValidationRules>
  <Required />
  </ValidationRules>
  </Property>
- <Property Name="_Name" DbColumnName="_Name" Description="" Type="string" DataType="AnsiString" NativeType="varchar" SystemType="System.String">
- <ValidationRules>
  <StringMaxLength>50</StringMaxLength>
  </ValidationRules>
  </Property>
- <Property Name="_CompanyID" DbColumnName="_CompanyID" Description="" Type="EditableChild.Company" DataType="EditableChild.Company" NativeType="EditableChild.Company" SystemType="EditableChild.Company">
  <ValidationRules />
  </Property>
- <Property Name="_TimeStamp" DbColumnName="_TimeStamp" Description="" Type="byte[]" DataType="Binary" NativeType="timestamp" SystemType="System.Byte[]">
- <ValidationRules>
  <Required />
  </ValidationRules>
  </Property>
  <Property Name="_Departments" DbColumnName="" Description="A collection of Departments" Type="ReadOnlyChildList.Departments" DataType="ReadOnlyChildList.Departments" NativeType="ReadOnlyChildList.Departments" SystemType="ReadOnlyChildList.Departments" />
  </Properties>
  <Relationship Parent="Company" />
  </Object>
- <Object Access="public" Type="EditableRoot" NameSpace="EditableRoot" Name="Building">
- <Properties>
- <Property Name="_ID" DbColumnName="_ID" Description="" Type="int" DataType="Int32" NativeType="int" SystemType="System.Int32" IsPrimaryKey="true" IsIdentity="true">
- <ValidationRules>
  <Required />
  </ValidationRules>
  </Property>
- <Property Name="_Name" DbColumnName="_Name" Description="" Type="string" DataType="AnsiString" NativeType="varchar" SystemType="System.String">
- <ValidationRules>
  <StringMaxLength>50</StringMaxLength>
  </ValidationRules>
  </Property>
- <Property Name="_CompanyID" DbColumnName="_CompanyID" Description="" Type="EditableChild.Company" DataType="EditableChild.Company" NativeType="EditableChild.Company" SystemType="EditableChild.Company">
  <ValidationRules />
  </Property>
- <Property Name="_TimeStamp" DbColumnName="_TimeStamp" Description="" Type="byte[]" DataType="Binary" NativeType="timestamp" SystemType="System.Byte[]">
- <ValidationRules>
  <Required />
  </ValidationRules>
  </Property>
  <Property Name="_Departments" DbColumnName="" Description="A collection of Departments" Type="EditableChildList.Departments" DataType="EditableChildList.Departments" NativeType="EditableChildList.Departments" SystemType="EditableChildList.Departments" />
  </Properties>
  </Object>
- <Object Access="public" Type="ReadOnlyChildList" NameSpace="ReadOnlyChildList" Name="Buildings">
- <Properties>
- <Property Name="_ID" DbColumnName="_ID" Description="" Type="int" DataType="Int32" NativeType="int" SystemType="System.Int32" IsPrimaryKey="true" IsIdentity="true">
- <ValidationRules>
  <Required />
  </ValidationRules>
  </Property>
- <Property Name="_Name" DbColumnName="_Name" Description="" Type="string" DataType="AnsiString" NativeType="varchar" SystemType="System.String">
- <ValidationRules>
  <StringMaxLength>50</StringMaxLength>
  </ValidationRules>
  </Property>
- <Property Name="_CompanyID" DbColumnName="_CompanyID" Description="" Type="int" DataType="Int32" NativeType="int" SystemType="System.Int32">
  <ValidationRules />
  </Property>
- <Property Name="_TimeStamp" DbColumnName="_TimeStamp" Description="" Type="byte[]" DataType="Binary" NativeType="timestamp" SystemType="System.Byte[]">
- <ValidationRules>
  <Required />
  </ValidationRules>
  </Property>
  </Properties>
  <Relationship Child="Building" Parent="Company" />
  </Object>
  </Objects>

rasupit replied on Wednesday, November 15, 2006

Will,
Just want to let you know that I'll look in to this.  I just came back from long vacation and still trying to recover from it.

Ricky

rasupit replied on Thursday, November 16, 2006

Will,

What built did use to generate the code, the data structure of the sample does not look like the one comming from any of the nightly builds

Ricky

wjcomeaux replied on Friday, November 17, 2006

Are you referring to the sample XML I provided above? Or some other sample? The XML above is some that I generated myself.

 

Will

rasupit replied on Tuesday, November 21, 2006

You have tags and properties that is not valid eq: <Required />, Description="" Type="int" DataType="Int32" NativeType="int" SystemType="System.Int32"

Make sure your xml file is validate against CslaProject.xsd.

Ricky

Copyright (c) Marimer LLC