Results 1 to 10 of 10

Thread: [RESOLVED] Converting from an XML model object to more useful class

Threaded View

  1. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    Re: Converting from an XML model object to more useful class

    Thanks for the info techgnome; that sounds logical enough in the general case...

    However, in this specific case a command may only ever have 0 or 1 ReadProtocol, that is the <ReadProtocol> element has maxoccurs=1 and minoccurs=0. Which is to say that a given command may either be readable or not, if it is readable, then it is read from using a certain protocol... a command cannot be read using multiple protocols as a command with a different protocol would be a different command. So perhaps your starting problem is sort of a non-problem in this case?

    Nevertheless, to follow it down to:

    xml Code:
    1. <ReadProtocol>
    2.   <Name>FooReadProtocolEnumMember</Name>
    3.   <ReadLength>10</ReadLength>
    4.   <ReadLengthIsVariable>False</ReadLengthIsVariable>
    5. </ReadProtocol>

    This brings an issue with friendly names for types. A <ReadProtocol> should probably map to a class ReadProtocol type. The type that collects possible read protocols for Name should probably be enum ReadProtocol. Now we have a type clash in the XSD (ReadProtocol simple type for the enum and same for complex type for the element with nested elements) and also for the C# (ReadProtocol for the enum and same for the class).

    Although the <ReadProtocol> complex type could possibly be anonymous (in the case where there is a maximum of 1 read protocol) but that looks bad, does not work if there are to be multiple read protocols and still does not solve the clash in C#. Unless the Name type was enum ReadProtocolName, but again that starts to seem ... clunky and as such seems like a code smell maybe?

    PS: I cannot just use Protocol for either the class or the enum type name to avoid this clash, because that would then clash with solving the same problem for the WriteProtocol which obviously has a different set of protocol names and so a different enum.
    Last edited by wolf99; Aug 24th, 2017 at 04:42 AM.
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width