mixed XML serialization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • andrewcw

    #1

    mixed XML serialization

    I have an object that serializes back and forth.
    I would like to have some objects not serialize ..and when
    I read that info back into the class, have this item be
    null ( or something like it ).

    I modified a class I made by XSD.exe by adding these
    values ( drvltr, disknum) , but I found when I wrote the
    class out to file and retrieved it, the values were
    persisted.

    If this is reasonable, how do I approach it ? Thanks

    In the example below, the tool inserts the declaration
    [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    for each attribute. Therefore I added the the attributes
    drvltr and disknum because I reasoned maybe without the
    declaration, they would be ignored.

    [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    public string uniqueid;
    public string drvltr;
    public string disknum;

  • Kevin Yu

    #2
    RE: mixed XML serialization

    Hi Andrew,

    To exclude a field of a class when serializing, you can add the following
    attribute before the declaration of this memeber variable. For example, if
    you don't want "disknum" to be serialized, you can try the following code:

    [System.NonSeria lized()]
    public string disknum;

    This attribute only affects on the declaration of "disknum", and will be
    ignored on latter fields.

    Does this answer your question? If anything is unclear, please feel free to
    reply to the post.

    Kevin Yu
    =======
    "This posting is provided "AS IS" with no warranties, and confers no
    rights."

    --------------------
    | Content-Class: urn:content-classes:message
    | From: "andrewcw" <andrew.c.watts @boeing.com>
    | Sender: "andrewcw" <andrew.c.watts @boeing.com>
    | Subject: mixed XML serialization
    | Date: Sun, 5 Oct 2003 20:01:54 -0700
    | Lines: 23
    | Message-ID: <00ac01c38bb6$3 2658a90$a001280 a@phx.gbl>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="iso-8859-1"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Thread-Index: AcOLtjJlFwrQ4RT LS9eveNRajrJ6Ew ==
    | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
    | Path: cpmsftngxa06.ph x.gbl
    | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1891 33
    | NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
    | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
    |
    | I have an object that serializes back and forth.
    | I would like to have some objects not serialize ..and when
    | I read that info back into the class, have this item be
    | null ( or something like it ).
    |
    | I modified a class I made by XSD.exe by adding these
    | values ( drvltr, disknum) , but I found when I wrote the
    | class out to file and retrieved it, the values were
    | persisted.
    |
    | If this is reasonable, how do I approach it ? Thanks
    |
    | In the example below, the tool inserts the declaration
    | [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    | for each attribute. Therefore I added the the attributes
    | drvltr and disknum because I reasoned maybe without the
    | declaration, they would be ignored.
    |
    | [System.Xml.Seri alization.XmlAt tributeAttribut e()]
    | public string uniqueid;
    | public string drvltr;
    | public string disknum;
    |
    |

    Comment

    • Kevin Yu

      #3
      RE: mixed XML serialization

      Hi Andrew,

      To exclude a field of a class when serializing, you can add the following
      attribute before the declaration of this memeber variable. For example, if
      you don't want "disknum" to be serialized, you can try the following code:

      [System.NonSeria lized()]
      public string disknum;

      This attribute only affects on the declaration of "disknum", and will be
      ignored on latter fields.

      Does this answer your question? If anything is unclear, please feel free to
      reply to the post.

      Kevin Yu
      =======
      "This posting is provided "AS IS" with no warranties, and confers no
      rights."

      --------------------
      | Content-Class: urn:content-classes:message
      | From: "andrewcw" <andrew.c.watts @boeing.com>
      | Sender: "andrewcw" <andrew.c.watts @boeing.com>
      | Subject: mixed XML serialization
      | Date: Sun, 5 Oct 2003 20:01:54 -0700
      | Lines: 23
      | Message-ID: <00ac01c38bb6$3 2658a90$a001280 a@phx.gbl>
      | MIME-Version: 1.0
      | Content-Type: text/plain;
      | charset="iso-8859-1"
      | Content-Transfer-Encoding: 7bit
      | X-Newsreader: Microsoft CDO for Windows 2000
      | Thread-Index: AcOLtjJlFwrQ4RT LS9eveNRajrJ6Ew ==
      | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
      | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
      | Path: cpmsftngxa06.ph x.gbl
      | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1891 33
      | NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
      | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
      |
      | I have an object that serializes back and forth.
      | I would like to have some objects not serialize ..and when
      | I read that info back into the class, have this item be
      | null ( or something like it ).
      |
      | I modified a class I made by XSD.exe by adding these
      | values ( drvltr, disknum) , but I found when I wrote the
      | class out to file and retrieved it, the values were
      | persisted.
      |
      | If this is reasonable, how do I approach it ? Thanks
      |
      | In the example below, the tool inserts the declaration
      | [System.Xml.Seri alization.XmlAt tributeAttribut e()]
      | for each attribute. Therefore I added the the attributes
      | drvltr and disknum because I reasoned maybe without the
      | declaration, they would be ignored.
      |
      | [System.Xml.Seri alization.XmlAt tributeAttribut e()]
      | public string uniqueid;
      | public string drvltr;
      | public string disknum;
      |
      |

      Comment

      • andrewcw

        #4
        RE: mixed XML serialization

        Thanks - that is exactly what I needed to know !!![color=blue]
        >-----Original Message-----
        >Hi Andrew,
        >
        >To exclude a field of a class when serializing, you can[/color]
        add the following[color=blue]
        >attribute before the declaration of this memeber[/color]
        variable. For example, if[color=blue]
        >you don't want "disknum" to be serialized, you can try[/color]
        the following code:[color=blue]
        >
        >[System.NonSeria lized()]
        >public string disknum;
        >
        >This attribute only affects on the declaration[/color]
        of "disknum", and will be[color=blue]
        >ignored on latter fields.
        >
        >Does this answer your question? If anything is unclear,[/color]
        please feel free to[color=blue]
        >reply to the post.
        >
        >Kevin Yu
        >=======
        >"This posting is provided "AS IS" with no warranties, and[/color]
        confers no[color=blue]
        >rights."
        >
        >--------------------
        >| Content-Class: urn:content-classes:message
        >| From: "andrewcw" <andrew.c.watts @boeing.com>
        >| Sender: "andrewcw" <andrew.c.watts @boeing.com>
        >| Subject: mixed XML serialization
        >| Date: Sun, 5 Oct 2003 20:01:54 -0700
        >| Lines: 23
        >| Message-ID: <00ac01c38bb6$3 2658a90$a001280 a@phx.gbl>
        >| MIME-Version: 1.0
        >| Content-Type: text/plain;
        >| charset="iso-8859-1"
        >| Content-Transfer-Encoding: 7bit
        >| X-Newsreader: Microsoft CDO for Windows 2000
        >| Thread-Index: AcOLtjJlFwrQ4RT LS9eveNRajrJ6Ew ==
        >| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
        >| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
        >| Path: cpmsftngxa06.ph x.gbl
        >| Xref: cpmsftngxa06.ph x.gbl[/color]
        microsoft.publi c.dotnet.langua ges.csharp:1891 33[color=blue]
        >| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
        >| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
        >|
        >| I have an object that serializes back and forth.
        >| I would like to have some objects not serialize ..and[/color]
        when[color=blue]
        >| I read that info back into the class, have this item be
        >| null ( or something like it ).
        >|
        >| I modified a class I made by XSD.exe by adding these
        >| values ( drvltr, disknum) , but I found when I wrote[/color]
        the[color=blue]
        >| class out to file and retrieved it, the values were
        >| persisted.
        >|
        >| If this is reasonable, how do I approach it ? Thanks
        >|
        >| In the example below, the tool inserts the declaration
        >| [System.Xml.Seri alization.XmlAt tributeAttribut e()]
        >| for each attribute. Therefore I added the the[/color]
        attributes[color=blue]
        >| drvltr and disknum because I reasoned maybe without the
        >| declaration, they would be ignored.
        >|
        >| [System.Xml.Seri alization.XmlAt tributeAttribut e()]
        >| public string uniqueid;
        >| public string drvltr;
        >| public string disknum;
        >|
        >|
        >
        >.
        >[/color]

        Comment

        • Daniel Pratt

          #5
          Re: mixed XML serialization

          Hi Andrew,

          "andrewcw" <andrew.c.watts @boeing.com> wrote in message
          news:2320c01c38 c1a$e0af9eb0$a6 01280a@phx.gbl. ..[color=blue]
          >
          > Kevin, something is not right, I modified the class file
          > and it wrote out the fields and read them back in:
          > here's what that portion of the class now reads: { What
          > could be the cause of that ??? } THANKS[/color]
          <snip>

          Use the "XmlIgnore" attribute on the field. The XmlIgnore attribute
          refers to XML serialization, whereas the NonSerialized attribute refers to
          binary serialization.

          Regards,
          Dan


          Comment

          • andrewcw

            #6
            Re: mixed XML serialization

            Thanks - I tested that and it worked:
            [XmlIgnoreAttrib ute]
            public string disknum;
            [color=blue]
            >-----Original Message-----
            >Hi Andrew,
            >
            >"andrewcw" <andrew.c.watts @boeing.com> wrote in message
            >news:2320c01c3 8c1a$e0af9eb0$a 601280a@phx.gbl ...[color=green]
            >>
            >> Kevin, something is not right, I modified the class[/color][/color]
            file[color=blue][color=green]
            >> and it wrote out the fields and read them back in:
            >> here's what that portion of the class now reads: { What
            >> could be the cause of that ??? } THANKS[/color]
            ><snip>
            >
            > Use the "XmlIgnore" attribute on the field. The[/color]
            XmlIgnore attribute[color=blue]
            >refers to XML serialization, whereas the NonSerialized[/color]
            attribute refers to[color=blue]
            >binary serialization.
            >
            >Regards,
            >Dan
            >
            >
            >.
            >[/color]

            Comment

            • Kevin Yu

              #7
              Re: mixed XML serialization

              Thanks, Daniel.

              Andrew, apologize for my mistake.

              Kevin Yu
              =======
              "This posting is provided "AS IS" with no warranties, and confers no
              rights."

              --------------------
              | Content-Class: urn:content-classes:message
              | From: "andrewcw" <andrew.c.watts @boeing.com>
              | Sender: "andrewcw" <andrew.c.watts @boeing.com>
              | References: <00ac01c38bb6$3 2658a90$a001280 a@phx.gbl>
              <MPDUwj9iDHA.19 28@cpmsftngxa06 .phx.gbl>
              <2320c01c38c1a$ e0af9eb0$a60128 0a@phx.gbl>
              <OVgvHOCjDHA.19 60@TK2MSFTNGP12 .phx.gbl>
              | Subject: Re: mixed XML serialization
              | Date: Mon, 6 Oct 2003 11:23:07 -0700
              | Lines: 29
              | Message-ID: <057e01c38c36$e 4161180$a101280 a@phx.gbl>
              | MIME-Version: 1.0
              | Content-Type: text/plain;
              | charset="iso-8859-1"
              | Content-Transfer-Encoding: 7bit
              | X-Newsreader: Microsoft CDO for Windows 2000
              | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
              | Thread-Index: AcOMNuQWrsIp/RrBSv6Q4v3XXQ5F Ig==
              | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
              | Path: cpmsftngxa06.ph x.gbl
              | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1893 32
              | NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
              | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
              |
              | Thanks - I tested that and it worked:
              | [XmlIgnoreAttrib ute]
              | public string disknum;
              |
              | >-----Original Message-----
              | >Hi Andrew,
              | >
              | >"andrewcw" <andrew.c.watts @boeing.com> wrote in message
              | >news:2320c01c3 8c1a$e0af9eb0$a 601280a@phx.gbl ...
              | >>
              | >> Kevin, something is not right, I modified the class
              | file
              | >> and it wrote out the fields and read them back in:
              | >> here's what that portion of the class now reads: { What
              | >> could be the cause of that ??? } THANKS
              | ><snip>
              | >
              | > Use the "XmlIgnore" attribute on the field. The
              | XmlIgnore attribute
              | >refers to XML serialization, whereas the NonSerialized
              | attribute refers to
              | >binary serialization.
              | >
              | >Regards,
              | >Dan
              | >
              | >
              | >.
              | >
              |

              Comment

              Working...