Quantcast
Channel: xsd2Code community edition .net class generator from XSD schema
Viewing all 543 articles
Browse latest View live

Commented Issue: The /eit flag does not work with xsd:include [15099]

$
0
0
The problem is the following:
* All schemas that are included have to have the same target namespace as the including schema (this is a requirement in XSD)
* Your ContainsTypeName method (in Xsd2Code.Library.Extensions.CodeExtension.cs) checks for namespace equality
 
Therefore ALL types in the XSD files (directly or through includes) are classified as directly in the same file by your logic. This should be fixed.
Comments: ** Comment from web user: jparson **

Keeping in mind that I don't have a lot of experience with XSD or CodeDom and have probably overlooked something, I have a fix for this.

I altered the Xsd2Code.Library.Extensions.CodeExtension.Process() function to compare the type names from the passed in XslSchema object and the type names contained in the XslSchema.Includes collection. If the names are in both locations, I remove it from the passed in CodeNamespace.Types object.

Original Code:
```
foreach (var type in types)
{
...

// Fixes http://xsd2code.codeplex.com/WorkItem/View.aspx?WorkItemId=8781
// and http://xsd2code.codeplex.com/WorkItem/View.aspx?WorkItemId=6944
if (GeneratorContext.GeneratorParams.Miscellaneous.ExcludeIncludedTypes)
{
//if the typeName is NOT defined in the current schema, skip it.
if (!ContainsTypeName(schema, type))
{
code.Types.Remove(type);
continue;
}
}

...

}
```

Altered Code:
```
List<String> lstBaseXmlTypes = new List<String>();
List<String> lstIncludedXmlTypes = new List<String>();

// Get all type names in the schema
foreach (var name in schema.SchemaTypes.Names)
lstBaseXmlTypes.Add(name.ToString());

// Get all type names from all schemas in the Includes collection
foreach (XmlSchemaInclude i in schema.Includes)

// loop through all schemas in the Includes collection
foreach (XmlSchemaInclude i in schema.Includes)
// Get all type names from each schema
foreach (var name in i.Schema.SchemaTypes.Names)
if (!lstIncludedXmlTypes.Contains(name.ToString()))
lstIncludedXmlTypes.Add(name.ToString());

foreach (var type in types)
{
...

if (GeneratorContext.GeneratorParams.Miscellaneous.ExcludeIncludedTypes)
{
// Remove types from the CodeDom if found in both type lists.
if (lstIncludedXmlTypes.Contains(type.Name) && lstBaseXmlTypes.Contains(type.Name))
{
code.Types.Remove(type);
continue;
}
}

...
}
```


Commented Issue: The /eit flag does not work with xsd:include [15099]

$
0
0
The problem is the following:
* All schemas that are included have to have the same target namespace as the including schema (this is a requirement in XSD)
* Your ContainsTypeName method (in Xsd2Code.Library.Extensions.CodeExtension.cs) checks for namespace equality
 
Therefore ALL types in the XSD files (directly or through includes) are classified as directly in the same file by your logic. This should be fixed.
Comments: ** Comment from web user: jparson **

I realized after posting that I didn't really explain why I chose the solution I did.

The current process removes all types that are not in the original XSD. The problem with this is that the code generation will sometimes create classes that aren't in the original XSD or any included XSDs. These types are created when there is a complex element declared in line in the XSD.

Example XSD element:
```
<element name="parent">
<complexType>
<element name="element1" type="String" />
<element name="elementNoType">
<complexType>
<element name="element2" type="String" />
</complexType>
</element>
</complexType>
</element>
```

The XSD element above will produce the following classes:
```
class Main
{
typeMain parent;
}

class typeMain
{
string element1;
typeMainElementNoType elementNoType;
}

class typeMainElementNoType
{
string element2;
}
```

typeMain and typeMainElementNoType are required in the final generated code. However, the current process will remove them.

I know that this can be corrected by moving the complexType declarations into named complexTypes, but this isn't always possible. Especially when you don't own the XSD and must simply use it as is.

Hopefully, this explains the need for the change to the program a little better.

New Post: Xsd2Code 2015+

$
0
0
Hi,
I found XSD2Code 2015+ addin via visual studio 2015. However, once i installed it, if i right click the xsd from solution explorer it is not giving the interface shown in the webpage i.e. Run xsd2code generation.

Did anyone experience the same thing and if so what is the resolution to the issue.

Thanks in advance for your all's time.
Viewing all 543 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>