in

Platinum Bay

Peace, Love and Visual Studio Team System

.NETicated

Xml Schemas

Ok, this is getting really frustrating. I frequently find myself needing to implement Xml Schemas within solutions I am building. I spent years working with ASP.old and VB.old, so I really like the whole notion of "Strongly-Typed", and I therefore want to generate code behind an XSD.

The first attempt for most people is to use XSD.exe, or MSDataSetGenerator in Visual Studio (which calls XSD.exe under the covers) to generate a dataset or classes from the XSD. Unfortunately, the functionality within XSD.exe is limited to what can be described in a database structure. Trying to work with more complex XSDs lead to dreaded error messages, like "The same table (row) cannot be the child table in two nested relations."

The next attempt is to search the web, thereby finding references to tools such as CodeXS. While these are great tools, they are not without their drawbacks either.

Take for example the following snippet:

<xsd:choice>
    <
xsd:sequence>
        <
xsd:element name="USERID" type="ofx:IdType" />
        <
xsd:element name="USERPASS" type="ofx:PasswordType" />
    </
xsd:sequence>
    <
xsd:element name="USERKEY" type="ofx:UserKeyType" />

</
xsd:choice>

CodeXS generates this as:

<System.Xml.Serialization.XmlElementAttribute("USERID", GetType(String), Form:=System.Xml.Schema.XmlSchemaForm.Unqualified), _
System.Xml.Serialization.XmlElementAttribute("USERKEY", GetType(String), Form:=System.Xml.Schema.XmlSchemaForm.Unqualified), _
System.Xml.Serialization.XmlElementAttribute("USERPASS", GetType(String), Form:=System.Xml.Schema.XmlSchemaForm.Unqualified),_
System.Xml.Serialization.XmlChoiceIdentifierAttribute("_ItemsElementName")> _
Public Property _Items() As String()
    Get
        Return
StringCollection.ToArray(Me.__Items)
    End Get
    Set
        Me
.__Items = StringCollection.FromArray(value)
    End Set
End
Property

<System.Xml.Serialization.XmlIgnoreAttribute()> _
Public Property Items() As StringCollection
    Get
        If
(Me.__Items Is Nothing) Then
            Me
.__Items = New StringCollection
        End If
        Return
Me.__Items
    End Get
    Set
        Me
.__Items = value
    End Set
End Property

While all the items are there, they are not exactly strongly typed. Upon digging further into the schema, and how it was generated, it appears that the generators have issues with elements using restricted SimpleTypes. I could certainly change the code to include each item as a property, but that defeats the purpose of "auto-generated".

Further, there is no support for the choice element, which defines that the message can include the USERID and USERPASS elements OR the USERKEY element.

This leads me to my final question; whose fault is it? Are the schema suppliers wrong? I don't think so, all of the schemas I have had problems with DO validate against the Xml Schema specification. So that leaves the developer tools. I have yet to find one that works perfectly. Mainly, I have used Visual Studio, Altova XMLSpy and CodeXS. All of which are excellent tools, but none of which were completely accurate.

For the record, here are the schemas and product version I refer to above:

Schemas:

  • OFX (Open Financial eXchange)
  • BPEL (Business Process Execution Language

Tools:

  • CodeXS Version 0.57 Beta
  • Visual Studio 2005 SP1
  • Altova XMLSpy 2006 rel. 3
Published Apr 19 2007, 06:26 AM by Steve
Filed under: , ,

Comments

December 18, 2007 6:51 AM

Dear Steve

I use Visual Studio 2005 SP1 and i have created a xsd with MSDataSetGenerator and it works wel also in designer but still when i want to load the dataset I get the error

"The same table 'node' cannot be the child table in two nested relations."

Do you know a solution to this bug, MS says that they have repared the bug with sp1?

connect.microsoft.com/.../ViewFeedback.aspx

Thanks in advance

freggel
 

January 1, 2008 7:16 PM

freggel, this is a known problem when working with XML schemas.  You have a couple options, though.  First, if you control the schema, make sure each node name is unique.  Second, there are third party tools such as CodeXS that you can try.

 

Leave a Comment

(required )  
(optional )
(required )  
Add

About Steve

Steve Andrews has been working as a developer for more than 8 years. During this time, he has designed and developed applications in such widely varying areas as trust accounting, medical information management, supply chain management, and retail systems. He has firsthand developer experience with a variety of languages, including Java, VB, and .NET. Most recently, he has been immersed in SharePoint. He is currently employed at RDA Corporation in Philadelphia, PA, as a Software Engineer and a team member in the Architectural Guidance evangelism team. Steve is also an MTCS (x2), ICSOO, and .NET fanatic.
Powered by Community Server (Commercial Edition), by Telligent Systems
© Platinum Bay | Some Rights Reserved Creative Commons License

Disclaimer: The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or annonymous comments) - so keep it polite, please.