XML and strongly typed datasets

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

    XML and strongly typed datasets

    I have a situation in which I have a strongly typed dataset based on the
    schema of a xml document. This works great, and OMG I love strongly typed
    datasets... ;o)

    However, The situation I have has a nested complex type. For example:

    <PAGE>
    <PAGENUMBER>1 </PAGENUMBER>
    <PAGETITLE>Th is is the title</PAGETITLE>
    <IMAGES>
    <IMAGE NAME="Image1" FILE="image1.jp g" />
    <IMAGE NAME="Image2" FILE="image2.jp g" />
    <IMAGE NAME="Image3" FILE="image3.jp g" />
    </IMAGES>
    </PAGE>

    (or something to that effect, you get the idea)

    Because the <Images> is a Complex type, I can not access it's members
    through the dataset. In other words, I can get the page title by saying
    "myDataset.Page (index).PAGETIT LE", but I can't get a image by saying
    something like: "myDataset.Page (index).Images( index2).File"

    I know you can manually build relationships in the dataset as long as there
    are unique keys in both the <IMAGE> and <PAGE> elements that can be joined
    on, (which is what I ended up doing) but it seems like there should be an
    easier way.

    Thanks a bunch for any advice!

    -D


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: XML and strongly typed datasets

    D,

    You aren't going to be able to access the representation of an image,
    because only a small set of types are represented in the dataset. What is
    really stored in the dataset is the serialized representation of a type.
    The types that are exposed are the types that are frequently used. In the
    case of the image, it is the binary representation.

    You should be able to save the image to disk, or load the array into
    memory and then use one of the static FromXXXX methods on the Image to get
    an object representation of that image.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m


    "MC D" <aspam@earthtal k.com> wrote in message
    news:e7RcsyokDH A.2488@TK2MSFTN GP12.phx.gbl...[color=blue]
    > I have a situation in which I have a strongly typed dataset based on the
    > schema of a xml document. This works great, and OMG I love strongly typed
    > datasets... ;o)
    >
    > However, The situation I have has a nested complex type. For example:
    >
    > <PAGE>
    > <PAGENUMBER>1 </PAGENUMBER>
    > <PAGETITLE>Th is is the title</PAGETITLE>
    > <IMAGES>
    > <IMAGE NAME="Image1" FILE="image1.jp g" />
    > <IMAGE NAME="Image2" FILE="image2.jp g" />
    > <IMAGE NAME="Image3" FILE="image3.jp g" />
    > </IMAGES>
    > </PAGE>
    >
    > (or something to that effect, you get the idea)
    >
    > Because the <Images> is a Complex type, I can not access it's members
    > through the dataset. In other words, I can get the page title by saying
    > "myDataset.Page (index).PAGETIT LE", but I can't get a image by saying
    > something like: "myDataset.Page (index).Images( index2).File"
    >
    > I know you can manually build relationships in the dataset as long as[/color]
    there[color=blue]
    > are unique keys in both the <IMAGE> and <PAGE> elements that can be joined
    > on, (which is what I ended up doing) but it seems like there should be an
    > easier way.
    >
    > Thanks a bunch for any advice!
    >
    > -D
    >
    >[/color]


    Comment

    • Alan Pretre

      #3
      Re: XML and strongly typed datasets

      "MC D" <aspam@earthtal k.com> wrote in message
      news:e7RcsyokDH A.2488@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Because the <Images> is a Complex type, I can not access it's members
      > through the dataset. In other words, I can get the page title by saying
      > "myDataset.Page (index).PAGETIT LE", but I can't get a image by saying
      > something like: "myDataset.Page (index).Images( index2).File"
      >
      > I know you can manually build relationships in the dataset as long as[/color]
      there[color=blue]
      > are unique keys in both the <IMAGE> and <PAGE> elements that can be joined
      > on, (which is what I ended up doing) but it seems like there should be an
      > easier way.
      >
      > Thanks a bunch for any advice![/color]

      What I do is put another dataset layer on top of the dataset generated by
      VS. Then you can create all kinds of overloads and whatnot to give you the
      abstraction that you want.

      For example,

      public class LoginsDataSet : LoginsDataSetVS {
      public object Image(int PageIndex, int ImageIndex){} // or whatever.
      public int FillBy1(whateve r){}
      public int FillBy2(whateve r){}
      }

      where LoginsDataSetVS is the class created by VS (in my code I have a
      convention of appending VS onto the class name for dataset classes generated
      by VS (ie the dataset name in Properties)).

      -- Alan


      Comment

      • MC D

        #4
        Re: XML and strongly typed datasets

        I guess I can see that...

        I guess, really, my point is that the dataset can see that there is a
        complex type within a complex type, so it knows that one property of the
        "PAGE" class will be a collection of "IMAGES", yet when I look at the code
        insight there is no collection for "images" _UNDERNEATH_ the <PAGE> level.,
        and I was wondering if there is an easier way to do this that I just wasn't
        seeing, since it's the first time I've done this.

        Thanks for everyones help.

        -D



        "Alan Pretre" <no@spam> wrote in message
        news:OkOAbGpkDH A.2776@tk2msftn gp13.phx.gbl...[color=blue]
        > "MC D" <aspam@earthtal k.com> wrote in message
        > news:e7RcsyokDH A.2488@TK2MSFTN GP12.phx.gbl...[color=green]
        > > Because the <Images> is a Complex type, I can not access it's members
        > > through the dataset. In other words, I can get the page title by saying
        > > "myDataset.Page (index).PAGETIT LE", but I can't get a image by saying
        > > something like: "myDataset.Page (index).Images( index2).File"
        > >
        > > I know you can manually build relationships in the dataset as long as[/color]
        > there[color=green]
        > > are unique keys in both the <IMAGE> and <PAGE> elements that can be[/color][/color]
        joined[color=blue][color=green]
        > > on, (which is what I ended up doing) but it seems like there should be[/color][/color]
        an[color=blue][color=green]
        > > easier way.
        > >
        > > Thanks a bunch for any advice![/color]
        >
        > What I do is put another dataset layer on top of the dataset generated by
        > VS. Then you can create all kinds of overloads and whatnot to give you[/color]
        the[color=blue]
        > abstraction that you want.
        >
        > For example,
        >
        > public class LoginsDataSet : LoginsDataSetVS {
        > public object Image(int PageIndex, int ImageIndex){} // or[/color]
        whatever.[color=blue]
        > public int FillBy1(whateve r){}
        > public int FillBy2(whateve r){}
        > }
        >
        > where LoginsDataSetVS is the class created by VS (in my code I have a
        > convention of appending VS onto the class name for dataset classes[/color]
        generated[color=blue]
        > by VS (ie the dataset name in Properties)).
        >
        > -- Alan
        >
        >[/color]


        Comment

        Working...