how to deserialize variable element/node

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wpmccormick@gmail.com

    how to deserialize variable element/node

    I've a complex problem:

    I'm deserializing a very long string of XML into a very large object
    foo:

    <foo>
    .......
    <bar>sometime s a simple string is here</bar>
    .......
    </foo>

    or sometimes it's

    <foo>
    .......
    <bar>
    <zip>sometime s</zip>
    <zap>more structure</zap>
    <zoo>is here</zoo>
    </bar>
    .......
    </foo>

    the foo class is either foo1

    class foo {
    ....
    string bar;
    ....
    }

    or foo2

    class foo {
    ...
    string bar[];
    ...
    }

    class bar {
    string zip;
    string zap;
    string zoo;
    }

    The short bar element is the only difference between the large foo1 and
    foo2.

    What is the best (ok, easiest; robust; fastest) way to do this?
    1. select the correct type
    2. remove the <bar>...</barfrom the string and deserialize separately
    3. use XMLAnyElement
    4. use the unknown element event

    Thanks,

    Bill

  • wpmccormick@gmail.com

    #2
    Re: how to deserialize variable element/node


    wpmccormick@gma il.com wrote:
    I've a complex problem:
    >
    Said a different way: i need an element that can be either a
    complexType or a string
    I'm deserializing a very long string of XML into a very large object
    foo:
    >
    <foo>
    .......
    <bar>sometime s a simple string is here</bar>
    .......
    </foo>
    >
    or sometimes it's
    >
    <foo>
    .......
    <bar>
    <zip>sometime s</zip>
    <zap>more structure</zap>
    <zoo>is here</zoo>
    </bar>
    .......
    </foo>
    >
    the foo class is either foo1
    >
    class foo {
    ...
    string bar;
    ...
    }
    >
    or foo2
    >
    class foo {
    ...
    string bar[];
    ...
    }
    >
    class bar {
    string zip;
    string zap;
    string zoo;
    }
    >
    The short bar element is the only difference between the large foo1 and
    foo2.
    >
    What is the best (ok, easiest; robust; fastest) way to do this?
    1. select the correct type
    2. remove the <bar>...</barfrom the string and deserialize separately
    3. use XMLAnyElement
    4. use the unknown element event
    >
    Thanks,
    >
    Bill

    Comment

    • Gadget

      #3
      Re: how to deserialize variable element/node

      On 15 Nov 2006 19:28:42 -0800, wpmccormick@gma il.com wrote:
      I've a complex problem:
      >
      I'm deserializing a very long string of XML into a very large object
      foo:
      >
      <foo>
      .......
      <bar>sometime s a simple string is here</bar>
      .......
      </foo>
      >
      or sometimes it's
      >
      <foo>
      .......
      <bar>
      <zip>sometime s</zip>
      <zap>more structure</zap>
      <zoo>is here</zoo>
      </bar>
      .......
      </foo>
      >
      the foo class is either foo1
      >
      class foo {
      ...
      string bar;
      ...
      }
      >
      or foo2
      >
      class foo {
      ...
      string bar[];
      ...
      }
      >
      class bar {
      string zip;
      string zap;
      string zoo;
      }
      >
      The short bar element is the only difference between the large foo1 and
      foo2.
      >
      What is the best (ok, easiest; robust; fastest) way to do this?
      1. select the correct type
      2. remove the <bar>...</barfrom the string and deserialize separately
      3. use XMLAnyElement
      4. use the unknown element event
      >
      Thanks,
      >
      Bill
      Well, this code doesn't quite make sense. Is bar a variable name or a
      class? 'string bar' is a string called bar, 'string bar[]' is an array of
      strings called bar, but then you've got a class called bar :)
      In .NET as far as I know there is no native way to have an XMLAnyElement
      stored in your XML, as it will always be escaped and stored as a string.
      If you *must* store 'raw' XML then you have to implement the ISerializable
      interface and perform your own XML stream read/write, and I do this in our
      product to store and retrieve XML marked-up freeform text (containing
      nested <Band <Itags etc.). It's messy, and should be avoided if
      possible.
      One problem in your description is that you give two definitions for foo. A
      class can be one or the other, but both can't exist unless they have
      different names, in which case your tags will be different so you will know
      the class type needed to recreate them.
      Remember that you don't have to use the built in serializers; you can write
      your own using XMLWriters and readers.

      Cheers,
      Gadget

      Comment

      • wpmccormick@gmail.com

        #4
        Re: how to deserialize variable element/node


        Gadget wrote:
        On 15 Nov 2006 19:28:42 -0800, wpmccormick@gma il.com wrote:
        >
        I've a complex problem:

        I'm deserializing a very long string of XML into a very large object
        foo:

        <foo>
        .......
        <bar>sometime s a simple string is here</bar>
        .......
        </foo>

        or sometimes it's

        <foo>
        .......
        <bar>
        <zip>sometime s</zip>
        <zap>more structure</zap>
        <zoo>is here</zoo>
        </bar>
        .......
        </foo>

        the foo class is either foo1

        class foo {
        ...
        string bar;
        ...
        }

        or foo2

        class foo {
        ...
        string bar[];
        ...
        }

        class bar {
        string zip;
        string zap;
        string zoo;
        }

        The short bar element is the only difference between the large foo1 and
        foo2.

        What is the best (ok, easiest; robust; fastest) way to do this?
        1. select the correct type
        2. remove the <bar>...</barfrom the string and deserialize separately
        3. use XMLAnyElement
        4. use the unknown element event

        Thanks,

        Bill
        >
        Well, this code doesn't quite make sense. Is bar a variable name or a
        class? 'string bar' is a string called bar, 'string bar[]' is an array of
        strings called bar, but then you've got a class called bar :)
        In .NET as far as I know there is no native way to have an XMLAnyElement
        stored in your XML, as it will always be escaped and stored as a string.
        If you *must* store 'raw' XML then you have to implement the ISerializable
        interface and perform your own XML stream read/write, and I do this in our
        product to store and retrieve XML marked-up freeform text (containing
        nested <Band <Itags etc.). It's messy, and should be avoided if
        possible.
        One problem in your description is that you give two definitions for foo. A
        class can be one or the other, but both can't exist unless they have
        different names, in which case your tags will be different so you will know
        the class type needed to recreate them.
        Remember that you don't have to use the built in serializers; you can write
        your own using XMLWriters and readers.
        >
        Cheers,
        Gadget
        I should not have started of with "I've a complex problem"; it's really
        rather simple. The solution, however, may involve some complexity.

        Anyway, I have a single class called foo. Into it, I want to
        deserialize XML for a schema which I do not control. The XML will
        sometimes have an element bar which is a string, and sometimes it will
        be complex data.

        <foo>
        .......
        <bar>sometime s a simple string is here</bar>
        .......
        </foo>

        OR

        (corrected)

        class foo {
        ...
        bar baz[];
        ...
        }

        class bar {
        string zip;
        string zap;
        string zoo;
        }

        Thanks for the reply :)

        Comment

        • wpmccormick@gmail.com

          #5
          Re: how to deserialize variable element/node


          wpmccormick@gma il.com wrote:
          Gadget wrote:
          On 15 Nov 2006 19:28:42 -0800, wpmccormick@gma il.com wrote:
          I've a complex problem:
          I need to re-explain this ...

          Whether I deserialize this:
          >
          <foo>
          .......
          <bar>sometime s a simple string is here</bar>
          .......
          </foo>
          >
          Or this:
          >
          <foo>
          .......
          <bar>
          <zip>sometime s</zip>
          <zap>more structure</zap>
          <zoo>is here</zoo>
          </bar>
          .......
          </foo>
          >
          I want to end up with an object

          class foo {
          string bar;
          baz[] Baz;
          }

          class {
          string zip;
          string zap;
          string zoo;
          }

          In the first deserialization case, bar = "sometimes a simple string is
          here" and Baz is null. In the second bar is null and zip, zap and zoo
          are filled in.

          Thanks

          Comment

          • Gadget

            #6
            Re: how to deserialize variable element/node

            On 16 Nov 2006 19:54:06 -0800, wpmccormick@gma il.com wrote:
            wpmccormick@gma il.com wrote:
            >Gadget wrote:
            >>On 15 Nov 2006 19:28:42 -0800, wpmccormick@gma il.com wrote:
            >>>
            >I've a complex problem:
            >
            I need to re-explain this ...
            >
            Whether I deserialize this:
            >>
            ><foo>
            > .......
            > <bar>sometime s a simple string is here</bar>
            > .......
            ></foo>
            >>
            >
            Or this:
            >>
            ><foo>
            > .......
            > <bar>
            > <zip>sometime s</zip>
            > <zap>more structure</zap>
            > <zoo>is here</zoo>
            > </bar>
            > .......
            ></foo>
            >>
            >
            I want to end up with an object
            >
            class foo {
            string bar;
            baz[] Baz;
            }
            >
            class {
            string zip;
            string zap;
            string zoo;
            }
            >
            In the first deserialization case, bar = "sometimes a simple string is
            here" and Baz is null. In the second bar is null and zip, zap and zoo
            are filled in.
            >
            Thanks
            OK, so I think you're either misunderstandin g XML or trying to use it in an
            unorthadox and incorrect manner.
            Your two XML fragments would have to be represented in an XML schema by
            specifying mixed content, as in one case <barcontains TEXT and in the
            other it contains a set of tags.
            Why do you feel the need to read this structure of data? Do you have an
            existing data set with this format strings, or are you responsible for
            creating the XML?
            Your comment that your problem is 'rather simple' is not true. Perhaps your
            requirements are, but you seem to have created a very awkward problem for
            yourself.
            In XML your zip/zap/zoo should be inside a pair of <baztags, so you
            should have either of the following:
            <foo>
            <bar />
            </baz>
            <zip>sometime s</zip>
            <zap>more structure</zap>
            <zoo>is here</zoo>
            </baz>
            </foo>

            <foo>
            <bar>sometime s a simple string is here</bar>
            <baz />
            </foo>

            This means you use the same class for 'foo'. In the first example there is
            no string in bar and in second case there is no object assigned to baz
            (it's null).
            When the deserializer looks at the XML it sees <bar>, reads that it has no
            content, and sets it to be empty.
            Next, it sees the tag <baz>, creates an instance of a baz, and reads the
            content tags, assigning each value to a property in the baz object via the
            reflection detected properties.
            If baz is an empty tag then the object is set to null.

            This weird mixing of meanings in XML produce ambiguity that the built-in
            serializer/deserializer can not resolve and won't even try to.

            Cheers,
            Gadget

            Comment

            • wpmccormick@gmail.com

              #7
              Re: how to deserialize variable element/node


              Gadget wrote:
              On 16 Nov 2006 19:54:06 -0800, wpmccormick@gma il.com wrote:
              >
              wpmccormick@gma il.com wrote:
              Gadget wrote:
              >On 15 Nov 2006 19:28:42 -0800, wpmccormick@gma il.com wrote:
              >>
              I've a complex problem:
              I need to re-explain this ...

              Whether I deserialize this:
              >
              <foo>
              .......
              <bar>sometime s a simple string is here</bar>
              .......
              </foo>
              >
              Or this:
              >
              <foo>
              .......
              <bar>
              <zip>sometime s</zip>
              <zap>more structure</zap>
              <zoo>is here</zoo>
              </bar>
              .......
              </foo>
              >
              I want to end up with an object

              class foo {
              string bar;
              baz[] Baz;
              }

              class {
              string zip;
              string zap;
              string zoo;
              }

              In the first deserialization case, bar = "sometimes a simple string is
              here" and Baz is null. In the second bar is null and zip, zap and zoo
              are filled in.

              Thanks
              >
              OK, so I think you're either misunderstandin g XML or trying to use it in an
              unorthadox and incorrect manner.
              Your two XML fragments would have to be represented in an XML schema by
              specifying mixed content, as in one case <barcontains TEXT and in the
              other it contains a set of tags.
              Why do you feel the need to read this structure of data? Do you have an
              existing data set with this format strings, or are you responsible for
              creating the XML?
              Your comment that your problem is 'rather simple' is not true. Perhaps your
              requirements are, but you seem to have created a very awkward problem for
              yourself.
              In XML your zip/zap/zoo should be inside a pair of <baztags, so you
              should have either of the following:
              <foo>
              <bar />
              </baz>
              <zip>sometime s</zip>
              <zap>more structure</zap>
              <zoo>is here</zoo>
              </baz>
              </foo>
              >
              <foo>
              <bar>sometime s a simple string is here</bar>
              <baz />
              </foo>
              >
              This means you use the same class for 'foo'. In the first example there is
              no string in bar and in second case there is no object assigned to baz
              (it's null).
              When the deserializer looks at the XML it sees <bar>, reads that it has no
              content, and sets it to be empty.
              Next, it sees the tag <baz>, creates an instance of a baz, and reads the
              content tags, assigning each value to a property in the baz object via the
              reflection detected properties.
              If baz is an empty tag then the object is set to null.
              >
              This weird mixing of meanings in XML produce ambiguity that the built-in
              serializer/deserializer can not resolve and won't even try to.
              >
              Cheers,
              Gadget
              I have an existing data set with this format and I have no control of
              it. The people that have forced it on me (and others who need to
              interface to their system) seem not to have a very good understanding
              and/or are using it in some unorthodox manner; perhaps in order to
              discourage deserialization ?

              So ... any ideas?

              Comment

              • Gadget

                #8
                Re: how to deserialize variable element/node

                On 17 Nov 2006 20:48:34 -0800, wpmccormick@gma il.com wrote:
                Gadget wrote:
                >On 16 Nov 2006 19:54:06 -0800, wpmccormick@gma il.com wrote:
                >>
                >>wpmccormick@gma il.com wrote:
                >>>Gadget wrote:
                >>>>On 15 Nov 2006 19:28:42 -0800, wpmccormick@gma il.com wrote:
                >>>>>
                >>>I've a complex problem:
                >>>
                >>I need to re-explain this ...
                >>>
                >>Whether I deserialize this:
                >>>>
                >>><foo>
                >>> .......
                >>> <bar>sometime s a simple string is here</bar>
                >>> .......
                >>></foo>
                >>>>
                >>>
                >>Or this:
                >>>>
                >>><foo>
                >>> .......
                >>> <bar>
                >>> <zip>sometime s</zip>
                >>> <zap>more structure</zap>
                >>> <zoo>is here</zoo>
                >>> </bar>
                >>> .......
                >>></foo>
                >>>>
                >>>
                >>I want to end up with an object
                >>>
                >>class foo {
                >> string bar;
                >> baz[] Baz;
                >>}
                >>>
                >>class {
                >> string zip;
                >> string zap;
                >> string zoo;
                >>}
                >>>
                >>In the first deserialization case, bar = "sometimes a simple string is
                >>here" and Baz is null. In the second bar is null and zip, zap and zoo
                >>are filled in.
                >>>
                >>Thanks
                >>
                >OK, so I think you're either misunderstandin g XML or trying to use it in an
                >unorthadox and incorrect manner.
                >Your two XML fragments would have to be represented in an XML schema by
                >specifying mixed content, as in one case <barcontains TEXT and in the
                >other it contains a set of tags.
                >Why do you feel the need to read this structure of data? Do you have an
                >existing data set with this format strings, or are you responsible for
                >creating the XML?
                >Your comment that your problem is 'rather simple' is not true. Perhaps your
                >requirements are, but you seem to have created a very awkward problem for
                >yourself.
                >In XML your zip/zap/zoo should be inside a pair of <baztags, so you
                >should have either of the following:
                ><foo>
                > <bar />
                > </baz>
                > <zip>sometime s</zip>
                > <zap>more structure</zap>
                > <zoo>is here</zoo>
                > </baz>
                ></foo>
                >>
                ><foo>
                > <bar>sometime s a simple string is here</bar>
                > <baz />
                ></foo>
                >>
                >This means you use the same class for 'foo'. In the first example there is
                >no string in bar and in second case there is no object assigned to baz
                >(it's null).
                >When the deserializer looks at the XML it sees <bar>, reads that it has no
                >content, and sets it to be empty.
                >Next, it sees the tag <baz>, creates an instance of a baz, and reads the
                >content tags, assigning each value to a property in the baz object via the
                >reflection detected properties.
                >If baz is an empty tag then the object is set to null.
                >>
                >This weird mixing of meanings in XML produce ambiguity that the built-in
                >serializer/deserializer can not resolve and won't even try to.
                >>
                >Cheers,
                > Gadget
                >
                I have an existing data set with this format and I have no control of
                it. The people that have forced it on me (and others who need to
                interface to their system) seem not to have a very good understanding
                and/or are using it in some unorthodox manner; perhaps in order to
                discourage deserialization ?
                >
                So ... any ideas?
                Yes, forget about serialization. You've been describing the classes you
                want to serialize/deserialize, but in fact you don't have the classes, you
                only have the dataset.
                A better way of asking for a solution is to say
                "I have a set of XML of the following format. What would be the easiest way
                of reading/writing this to an object". Asking it by telling us the classes
                you've decided on is really muddying the water.

                I find it difficult to believe any company with XML know-how would provide
                you with XML in both of formats you describe:

                <foo>
                .......
                <bar>sometime s a simple string is here</bar>
                .......
                </foo>

                OR

                <foo>
                .......
                <bar>
                <zip>sometime s</zip>
                <zap>more structure</zap>
                <zoo>is here</zoo>
                </bar>
                .......
                </foo>

                This is a very bizarre way for them to serialize data, so can I suggest you
                post two samples of the *actual* data so we can see the real structure?

                Cheers,
                Gadget

                Comment

                • wpmccormick@gmail.com

                  #9
                  Re: how to deserialize variable element/node


                  Gadget wrote:
                  On 17 Nov 2006 20:48:34 -0800, wpmccormick@gma il.com wrote:
                  >
                  Gadget wrote:
                  On 16 Nov 2006 19:54:06 -0800, wpmccormick@gma il.com wrote:
                  >
                  >wpmccormick@gma il.com wrote:
                  >>Gadget wrote:
                  >>>On 15 Nov 2006 19:28:42 -0800, wpmccormick@gma il.com wrote:
                  >>>>
                  >>I've a complex problem:
                  >>
                  >I need to re-explain this ...
                  >>
                  >Whether I deserialize this:
                  >>>
                  >><foo>
                  >> .......
                  >> <bar>sometime s a simple string is here</bar>
                  >> .......
                  >></foo>
                  >>>
                  >>
                  >Or this:
                  >>>
                  >><foo>
                  >> .......
                  >> <bar>
                  >> <zip>sometime s</zip>
                  >> <zap>more structure</zap>
                  >> <zoo>is here</zoo>
                  >> </bar>
                  >> .......
                  >></foo>
                  >>>
                  >>
                  >I want to end up with an object
                  >>
                  >class foo {
                  > string bar;
                  > baz[] Baz;
                  >}
                  >>
                  >class {
                  > string zip;
                  > string zap;
                  > string zoo;
                  >}
                  >>
                  >In the first deserialization case, bar = "sometimes a simple string is
                  >here" and Baz is null. In the second bar is null and zip, zap and zoo
                  >are filled in.
                  >>
                  >Thanks
                  >
                  OK, so I think you're either misunderstandin g XML or trying to use it in an
                  unorthadox and incorrect manner.
                  Your two XML fragments would have to be represented in an XML schema by
                  specifying mixed content, as in one case <barcontains TEXT and in the
                  other it contains a set of tags.
                  Why do you feel the need to read this structure of data? Do you have an
                  existing data set with this format strings, or are you responsible for
                  creating the XML?
                  Your comment that your problem is 'rather simple' is not true. Perhaps your
                  requirements are, but you seem to have created a very awkward problem for
                  yourself.
                  In XML your zip/zap/zoo should be inside a pair of <baztags, so you
                  should have either of the following:
                  <foo>
                  <bar />
                  </baz>
                  <zip>sometime s</zip>
                  <zap>more structure</zap>
                  <zoo>is here</zoo>
                  </baz>
                  </foo>
                  >
                  <foo>
                  <bar>sometime s a simple string is here</bar>
                  <baz />
                  </foo>
                  >
                  This means you use the same class for 'foo'. In the first example there is
                  no string in bar and in second case there is no object assigned to baz
                  (it's null).
                  When the deserializer looks at the XML it sees <bar>, reads that it has no
                  content, and sets it to be empty.
                  Next, it sees the tag <baz>, creates an instance of a baz, and reads the
                  content tags, assigning each value to a property in the baz object via the
                  reflection detected properties.
                  If baz is an empty tag then the object is set to null.
                  >
                  This weird mixing of meanings in XML produce ambiguity that the built-in
                  serializer/deserializer can not resolve and won't even try to.
                  >
                  Cheers,
                  Gadget
                  I have an existing data set with this format and I have no control of
                  it. The people that have forced it on me (and others who need to
                  interface to their system) seem not to have a very good understanding
                  and/or are using it in some unorthodox manner; perhaps in order to
                  discourage deserialization ?

                  So ... any ideas?
                  >
                  Yes, forget about serialization. You've been describing the classes you
                  want to serialize/deserialize, but in fact you don't have the classes, you
                  only have the dataset.
                  A better way of asking for a solution is to say
                  "I have a set of XML of the following format. What would be the easiest way
                  of reading/writing this to an object". Asking it by telling us the classes
                  you've decided on is really muddying the water.
                  >
                  I find it difficult to believe any company with XML know-how would provide
                  you with XML in both of formats you describe:
                  >
                  <foo>
                  .......
                  <bar>sometime s a simple string is here</bar>
                  .......
                  </foo>
                  >
                  OR
                  >
                  <foo>
                  .......
                  <bar>
                  <zip>sometime s</zip>
                  <zap>more structure</zap>
                  <zoo>is here</zoo>
                  </bar>
                  .......
                  </foo>
                  >
                  This is a very bizarre way for them to serialize data, so can I suggest you
                  post two samples of the *actual* data so we can see the real structure?
                  >
                  Cheers,
                  Gadget
                  Again, the issue is DESERIALIZATION , not serialization.

                  This is from their spec. The issue is the <message_string node; it
                  will either be a simple string or complex. I can deserialize this but
                  only if I do so into the correct object.

                  <?xml version="1.0"?>
                  <tms_msg
                  xmlns:xsd="http ://www.w3.org/2001/XMLSchema"xmlns :xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <trans_id>Strin g(38)</trans_ID>
                  <veh_fleet_code >String(4)</veh_fleet_code>
                  <veh_radio_code >String(10)</veh_radio_code>
                  <protocol_versi on>String(2)</protocol_versio n>
                  <packet_code>St ring(3)</packet_code>
                  <transaction>
                  <trans_date_tim e>DateTime (yyyy-mm-ddThh:nn:ss)</trans_date_time >
                  <date_time_offs et>Integer(4)</date_time_offse t>
                  <tkt_code>Strin g(12)</tkt_code>
                  <order_code>Str ing(50)</order_code>
                  <tkt_date_time> DateTime (yyyy-mm-ddThh:nn:ss)</tkt_date_time>
                  <truck_code>Str ing(10)</truck_code>
                  <employee_code> String(12)</employee_code>
                  <message_string >String (5000)</message_string>
                  <message>Stri ng (5000)</message>
                  <trans_cat>Stri ng(4)</trans_cat>
                  <trans_type>Str ing(3)</trans_type>
                  <trans_sub_type >String(3)</trans_sub_type>
                  <trans_origin>S tring(3)</trans_origin>
                  <trans_origin_I PAddr>String(15 )</trans_origin_IP Addr>
                  <trans_origin_m achname>String( 32)</trans_origin_ma chname>
                  <trans_origin_u sername>String( 25)</trans_origin_us ername>
                  <time_to_live>I nteger(4)</time_to_live>
                  </transaction>
                  </tms_msg>

                  Comment

                  • John Saunders

                    #10
                    Re: how to deserialize variable element/node

                    <wpmccormick@gm ail.comwrote in message
                    news:1163994268 .167397.147480@ e3g2000cwe.goog legroups.com...
                    >
                    ....
                    Again, the issue is DESERIALIZATION , not serialization.
                    >
                    This is from their spec. The issue is the <message_string node; it
                    will either be a simple string or complex. I can deserialize this but
                    only if I do so into the correct object.
                    >
                    <?xml version="1.0"?>
                    <tms_msg
                    xmlns:xsd="http ://www.w3.org/2001/XMLSchema"xmlns :xsi="http://www.w3.org/2001/XMLSchema-instance">
                    <trans_id>Strin g(38)</trans_ID>
                    <veh_fleet_code >String(4)</veh_fleet_code>
                    <veh_radio_code >String(10)</veh_radio_code>
                    <protocol_versi on>String(2)</protocol_versio n>
                    <packet_code>St ring(3)</packet_code>
                    <transaction>
                    <trans_date_tim e>DateTime (yyyy-mm-ddThh:nn:ss)</trans_date_time >
                    <date_time_offs et>Integer(4)</date_time_offse t>
                    <tkt_code>Strin g(12)</tkt_code>
                    <order_code>Str ing(50)</order_code>
                    <tkt_date_time> DateTime (yyyy-mm-ddThh:nn:ss)</tkt_date_time>
                    <truck_code>Str ing(10)</truck_code>
                    <employee_code> String(12)</employee_code>
                    <message_string >String (5000)</message_string>
                    <message>Stri ng (5000)</message>
                    <trans_cat>Stri ng(4)</trans_cat>
                    <trans_type>Str ing(3)</trans_type>
                    <trans_sub_type >String(3)</trans_sub_type>
                    <trans_origin>S tring(3)</trans_origin>
                    <trans_origin_I PAddr>String(15 )</trans_origin_IP Addr>
                    <trans_origin_m achname>String( 32)</trans_origin_ma chname>
                    <trans_origin_u sername>String( 25)</trans_origin_us ername>
                    <time_to_live>I nteger(4)</time_to_live>
                    </transaction>
                    </tms_msg>
                    As another poster mentioned, this is clearly an organization which does not
                    understand XML. They should have sent you a schema instead of this pseudo
                    instance document.

                    Ask them if they have any example code (in any language) for serializing and
                    deserializing this format. Also, ask them if they have an actual schema, as
                    they at least seem to know the correct namespace for that.

                    John


                    Comment

                    • wpmccormick@gmail.com

                      #11
                      Re: how to deserialize variable element/node

                      John Saunders wrote:
                      <wpmccormick@gm ail.comwrote in message
                      news:1163994268 .167397.147480@ e3g2000cwe.goog legroups.com...
                      ...
                      Again, the issue is DESERIALIZATION , not serialization.

                      This is from their spec. The issue is the <message_string node; it
                      will either be a simple string or complex. I can deserialize this but
                      only if I do so into the correct object.

                      <?xml version="1.0"?>
                      <tms_msg
                      xmlns:xsd="http ://www.w3.org/2001/XMLSchema"xmlns :xsi="http://www.w3.org/2001/XMLSchema-instance">
                      <trans_id>Strin g(38)</trans_ID>
                      <veh_fleet_code >String(4)</veh_fleet_code>
                      <veh_radio_code >String(10)</veh_radio_code>
                      <protocol_versi on>String(2)</protocol_versio n>
                      <packet_code>St ring(3)</packet_code>
                      <transaction>
                      <trans_date_tim e>DateTime (yyyy-mm-ddThh:nn:ss)</trans_date_time >
                      <date_time_offs et>Integer(4)</date_time_offse t>
                      <tkt_code>Strin g(12)</tkt_code>
                      <order_code>Str ing(50)</order_code>
                      <tkt_date_time> DateTime (yyyy-mm-ddThh:nn:ss)</tkt_date_time>
                      <truck_code>Str ing(10)</truck_code>
                      <employee_code> String(12)</employee_code>
                      <message_string >String (5000)</message_string>
                      <message>Stri ng (5000)</message>
                      <trans_cat>Stri ng(4)</trans_cat>
                      <trans_type>Str ing(3)</trans_type>
                      <trans_sub_type >String(3)</trans_sub_type>
                      <trans_origin>S tring(3)</trans_origin>
                      <trans_origin_I PAddr>String(15 )</trans_origin_IP Addr>
                      <trans_origin_m achname>String( 32)</trans_origin_ma chname>
                      <trans_origin_u sername>String( 25)</trans_origin_us ername>
                      <time_to_live>I nteger(4)</time_to_live>
                      </transaction>
                      </tms_msg>
                      >
                      As another poster mentioned, this is clearly an organization which does not
                      understand XML. They should have sent you a schema instead of this pseudo
                      instance document.
                      >
                      Ask them if they have any example code (in any language) for serializing and
                      deserializing this format. Also, ask them if they have an actual schema, as
                      they at least seem to know the correct namespace for that.
                      >
                      John
                      Thanks John.

                      Regardless of what or how much they understand or what they could or
                      should provide, it is what it is; I seem to have no choice but to work
                      with this as is and with what they have provided.

                      There is either a way to directly deserialize this (the variable
                      message_string tag) or there is not. One option that I'm seriously
                      considering is to remove the <message_string contents before I
                      deserialize and process it seperately.

                      Thanks,

                      Bill

                      Comment

                      • Gadget

                        #12
                        Re: how to deserialize variable element/node

                        OK, ignoring the fact that (as John pointed out) this is a dreadful way to
                        'document' the format of the data...

                        Firstly, it makes no difference whether you are trying to serialize or
                        deserialize. Exactly the same problems occurr with XML data structures.

                        Secondly, assuming you do receive data in this format then the contents of
                        that string *cannot* be complex XML. They may indeed have some of their own
                        'markup' in that section, but it does not make up part of the tms_msg
                        packet, and can be classed as its own subset of XML data.

                        For example, if they want to give you a message
                        "An apalling document"
                        then they will provide:
                        :
                        <employee_code> 12345</employee_code>
                        <message_string >An apalling document</message_string>
                        <message>And this is another message thing</message>
                        :

                        If however they decide to have 'markup' in there and return
                        "An <B>apalling</Bdocument"
                        then they will provide
                        :
                        <employee_code> 12345</employee_code>
                        <message_string >An &lt;B&gt;apalli ng&lt;/B&gt; document</message_string>
                        <message>And this is another message thing</message>
                        :

                        This is the rule of XML. If you are placing a string (as they say,
                        string(5000)) in your document then they *must* escape the codes.
                        This is not a problem for you, and .NET handles this all automatically.
                        I've appended a pair of classes below that should serialize and deserialize
                        to their format of data.

                        If you like you can post an *actual sample* of their data to confirm what
                        I'm interpretting from their document.

                        Cheers,
                        Gadget


                        [Serializable]
                        public class tms_msg
                        {
                        private string _trans_id;

                        public string trans_id
                        {
                        get { return _trans_id; }
                        set { _trans_id = value; }
                        }
                        private string _veh_fleet_code ;

                        public string veh_fleet_code
                        {
                        get { return _veh_fleet_code ; }
                        set { _veh_fleet_code = value; }
                        }
                        private string _veh_radio_code ;

                        public string veh_radio_code
                        {
                        get { return _veh_radio_code ; }
                        set { _veh_radio_code = value; }
                        }
                        private string _protocol_versi on;

                        public string protocol_versio n
                        {
                        get { return _protocol_versi on; }
                        set { _protocol_versi on = value; }
                        }
                        private string _packet_code;

                        public string packet_code
                        {
                        get { return _packet_code; }
                        set { _packet_code = value; }
                        }
                        private transaction _subTransaction ;

                        public transaction subTransaction
                        {
                        get { return _subTransaction ; }
                        set { _subTransaction = value; }
                        }
                        }

                        public class transaction
                        {
                        private DateTime _trans_date_tim e;
                        public DateTime trans_date_time
                        {
                        get { return _trans_date_tim e; }
                        set { _trans_date_tim e = value; }
                        }
                        private int _date_time_offs et;

                        public int date_time_offse t
                        {
                        get { return _date_time_offs et; }
                        set { _date_time_offs et = value; }
                        }
                        private string _tkt_code;

                        public string tkt_code
                        {
                        get { return _tkt_code; }
                        set { _tkt_code = value; }
                        }
                        private string _order_code;

                        public string order_code
                        {
                        get { return _order_code; }
                        set { _order_code = value; }
                        }
                        private DateTime _tkt_date_time;

                        public DateTime tkt_date_time
                        {
                        get { return _tkt_date_time; }
                        set { _tkt_date_time = value; }
                        }
                        private string _truck_code;

                        public string truck_code
                        {
                        get { return _truck_code; }
                        set { _truck_code = value; }
                        }
                        private string _employee_code;

                        public string employee_code
                        {
                        get { return _employee_code; }
                        set { _employee_code = value; }
                        }
                        private string _message_string ;

                        public string message_string
                        {
                        get { return _message_string ; }
                        set { _message_string = value; }
                        }
                        private string _message;

                        public string message
                        {
                        get { return _message; }
                        set { _message = value; }
                        }
                        private string _trans_cat;

                        public string trans_cat
                        {
                        get { return _trans_cat; }
                        set { _trans_cat = value; }
                        }
                        private string _trans_type;

                        public string trans_type
                        {
                        get { return _trans_type; }
                        set { _trans_type = value; }
                        }
                        private string _trans_sub_type ;

                        public string trans_sub_type
                        {
                        get { return _trans_sub_type ; }
                        set { _trans_sub_type = value; }
                        }
                        private string _trans_origin;

                        public string trans_origin
                        {
                        get { return _trans_origin; }
                        set { _trans_origin = value; }
                        }
                        private string _trans_origin_I PAddr;

                        public string trans_origin_IP Addr
                        {
                        get { return _trans_origin_I PAddr; }
                        set { _trans_origin_I PAddr = value; }
                        }
                        private string _trans_origin_m achname;

                        public string trans_origin_ma chname
                        {
                        get { return _trans_origin_m achname; }
                        set { _trans_origin_m achname = value; }
                        }
                        private string _trans_origin_u sername;

                        public string trans_origin_us ername
                        {
                        get { return _trans_origin_u sername; }
                        set { _trans_origin_u sername = value; }
                        }
                        private int _time_to_live;

                        public int time_to_live
                        {
                        get { return _time_to_live; }
                        set { _time_to_live = value; }
                        }
                        }

                        Comment

                        Working...