0

This is an example of an XSD for one of the templates that will be stored in the database. The "to_email", "first_name" etc are all tokens and I need to dynamically create a dictionary or an object that can be returned to the client that will give a list of these tokens. The idea behind this is if there is any change in a template then we will just insert another value in the database and it should automatically be created dynamically for returning it to client when they will query for this template. How do I go about creating/parsing this? I don't want create a class object with individual element as that would mean that I will have to change it for every addition of the elements. So it has to be something generic.
We should be able to return the set as JSON or XML based on what the client asks for. How do I go about doing this? Any help would be appreciated. Thank you in advance.

   <?xml version="1.0" encoding="utf-8"?>
     <xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"  
      elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" 
       xmlns:mstns="http://tempuri.org/XMLSchema.xsd" 
          xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="claim">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="to_email" type="xs:string"/>
      <xs:element name="first_name" type="xs:string"/>
      <xs:element name="last_name" type="xs:string"/>
      <xs:element name="url" type="xs:string"/>
      <xs:element name="received_date" type="xs:date"/>
      <xs:element name="contact_number" type="xs:string"/>
      <xs:element name="employer_name" type="xs:string"/>
      <xs:element name="er_label" type="xs:string"/>
      <xs:element name="er_flag" type="xs:integer"/>
      <xs:element name="benefit_id" type="xs:integer"/>
      <xs:element name="employee_id" type="xs:integer"/>
      <xs:element name="employer_id" type="xs:integer"/>
      <xs:element name="form_id" type="xs:integer"/>
      <xs:element name="er_url" type="xs:string"/>
      <xs:element name="tax" type="xs:string"/>
      <xs:element name="Repeater" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="form_id" type="xs:integer"/>
            <xs:element name="amount" type="xs:integer"/>
            <xs:element name="expense_name" type="xs:string"/>
            <xs:element name="date_of_service" type="xs:string"/>
            <xs:element name="status_of_claim" type="xs:string"/>
            <xs:element name="status_reason"/>
            <xs:element name="Order_by" type="xs:integer"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
   </xs:complexType>
 </xs:element>
</xs:schema>

Adding further comments:

The response to the client should be something like each property of the object representing a field. For example a object.

{
  ‘field1’: <FieldDefinition>
  ‘field2’: <FieldDefinition>
  ‘field3’: <FieldDefinition>
  .
  .
  .
}

The object would contains the following properties like Type for example if it is a string or int, Display name i.e. the internal name could be first_name but the display name would FirstName# etc. Also the could be an array as well. So this makes it little more complex.

Am I making any sense?

Ditty
  • 521
  • 7
  • 24
  • They want something like each property of the object represents a field. For example a object. { ‘field1’: ‘field2’: ‘field3’: . . . } The object would contains the following properties like Type for example if it is a string or int, Display name i.e. the internal name could be first_name but the display name would FirstName# etc. Also the could be an array as well. So this makes it little more complex. – Ditty Jul 10 '14 at 18:19

3 Answers3

0

You generate classes for them using the xsd.exe util

Seen here: How to generate .NET 4.0 classes from xsd?

xsd your.xsd /classes
Community
  • 1
  • 1
Geoff
  • 210
  • 2
  • 3
  • 10
0

You can parse your template using XPath query or any generic XML processing. For any template change, you can opt for CacheDependency for File. You just cache the whole xml and if any changes to the tag/file then you insert that portion to the database and reload the cache. You can try SQLDependency also to get similar work.

Another option, you can go for filesystemwatcher which will raise event for changing in the file content. Then you just need to insert the added portion in the database.

0

I believe you can do the XML processing or you can find that in Google. Plenty of examples are there. I just added the code for logic you have mentioned for the properties. //Your XML processing

        var fields = new List<FieldDefinition>
        {
            new FieldDefinition{ Type="string", DisplayName="FirstName"},
            new FieldDefinition{ Type="int", DisplayName="EmployeeId"}
        };

        var infr = new List<Infrastructure>
        {
            new Infrastructure { def1=fields.FirstOrDefault()}// loop through to assign each item
        };
        foreach (var item in infr)
        Console.WriteLine(item.def1.DisplayName + " -" + item.def1.Type);

        Console.Read();

    }
}

public class Infrastructure
{
    public FieldDefinition def1 { get; set; }


}

public class FieldDefinition
{
    public string Type { get; set; }
    public string DisplayName { get; set; }
}