Validating Dynamic XML structures

  c#, javascript, validation, xml

I’ve taken over support for a web application that uses a dynamic xml data blob to persist the details of user data collection. This data comes from an AngularJs front end that calls into a .NET MVC backend for additional processing. There are validation routines at both ends, but there’s no defined schema, just a series of business rules embedded in the logic (also repeated at both ends). Since the XML blob is dynamic, the structure could be different each time. One of things we run into regularly is, when there is a change to this structure, existing records need to be massaged in someway to fit the new format or have old records expired requiring users to re-enter data (a truly awful user experience). I’m thinking a static structure or defined schema might help in this regard for deserialization at both ends to allow different "versions" of schemas to co-exist. Thoughts on how I could approach this are appreciated.

   <root type="object">
  <addresses type="array">
    <item type="object">
      <id type="string">f5bffa84-54cd-4789-a57f-b222415d79c1</id>
      <streetNumber type="string">20</streetNumber>
      <streetAddress type="string">Nowhere place</streetAddress>
      <streetAddress2 type="null" />
      <aptNumber type="null" />
      <city type="string">Noplace</city>
      <country type="string">usa</country>
      <state type="string">ny</state>
      <otherCountry type="null" />
      <zip type="string">L6X4W6</zip>
    </item>
  </addresses>
  <userEmail type="string">[email protected]</userEmail>
  <userFirstName type="string">Agent First Name36895</userFirstName>
  <userLastName type="string">Agent Last Name36895</userLastName>
  <bankingInformation type="array">
    <item type="object">
      <bankAccountType type="string">x</bankAccountType>
      <bankNumber type="string">555</bankNumber>
      <branchNumber type="string">55555</branchNumber>
      <accountNumber type="string">111111111111</accountNumber>
    </item>
  </bankingInformation>
  <attribute1 type="string">dependent on country</attribute1>
  <attribute2 type="string">dependent on attribute1 but may or may not appear</attribute2>
  ...
  <attributeN type="string">may or may not appear depending on business rules in the application</attributeN>
</root>

Source: Ask Javascript Questions

LEAVE A COMMENT