Retrieve attributes from xml document using typed dataset

Discussion in 'Microsoft ADO .NET' started by Guest, Mar 7, 2005.

  1. Guest

    Guest Guest

    I have an XML document that stores configuration settings for an app. I
    generated the schema using vs.net and also the corresponding dataset. I can
    load the config file (config.xml - below) and get all the data except for the
    element attribute values. I cannot figure out why the attribute values return
    a value of system.dbnull when the file contains values for those attributes.
    The code is as follows:

    config loader .vb


    Dim dsConfiguration As New Config

    dsConfiguration.ReadXml(Server.MapPath("Config.xml"))

    'I cannot get the following attribute value title

    Response.Write(dsConfiguration.Page(0).Title)

    'but this works fine

    Response.Write(dsConfiguration.JavaAttribute(0).AttributeName)




    config.xml


    <?xml version="1.0" encoding="utf-8" ?>

    <Config xmlns="http://tempuri.org/Config.xsd">

    <Page Title="Some title">

    <MetaTag>

    <Attribute AttributeName="something" Value="skdj" />

    </MetaTag>

    <JavaScript Path="/script.js">

    <JavaAttribute>

    <AttributeName>language</AttributeName>

    <Value>JavaScript</Value>

    </JavaAttribute>

    </JavaScript>

    <StyleSheet Path="/style.css">

    <StyleAttribute>

    <AttributeName>rel</AttributeName>

    <Value>stylesheet</Value>

    </StyleAttribute>

    <StyleAttribute>

    <AttributeName>type</AttributeName>

    <Value>text/css</Value>

    </StyleAttribute>

    </StyleSheet>

    </Page>

    </Config>
     
    Guest, Mar 7, 2005
    #1
    1. Advertisements

  2. Guest

    Sahil Malik Guest

    Dim dsConfiguration As New Config

    <--- What kind of object is Config?

    I'm assuming that is your strongly typed dataset?

    Why the below is happening depends on your schema. Not every schema is
    directly mapped to a dataset, i.e. Not every schema qualifies to be a
    dataset.

    - Sahil Malik
    http://codebetter.com/blogs/sahil.malik/




    "Anon" <> wrote in message
    news:...
    > I have an XML document that stores configuration settings for an app. I
    > generated the schema using vs.net and also the corresponding dataset. I

    can
    > load the config file (config.xml - below) and get all the data except for

    the
    > element attribute values. I cannot figure out why the attribute values

    return
    > a value of system.dbnull when the file contains values for those

    attributes.
    > The code is as follows:
    >
    > config loader .vb
    >
    >
    > Dim dsConfiguration As New Config
    >
    > dsConfiguration.ReadXml(Server.MapPath("Config.xml"))
    >
    > 'I cannot get the following attribute value title
    >
    > Response.Write(dsConfiguration.Page(0).Title)
    >
    > 'but this works fine
    >
    > Response.Write(dsConfiguration.JavaAttribute(0).AttributeName)
    >
    >
    >
    >
    > config.xml
    >
    >
    > <?xml version="1.0" encoding="utf-8" ?>
    >
    > <Config xmlns="http://tempuri.org/Config.xsd">
    >
    > <Page Title="Some title">
    >
    > <MetaTag>
    >
    > <Attribute AttributeName="something" Value="skdj" />
    >
    > </MetaTag>
    >
    > <JavaScript Path="/script.js">
    >
    > <JavaAttribute>
    >
    > <AttributeName>language</AttributeName>
    >
    > <Value>JavaScript</Value>
    >
    > </JavaAttribute>
    >
    > </JavaScript>
    >
    > <StyleSheet Path="/style.css">
    >
    > <StyleAttribute>
    >
    > <AttributeName>rel</AttributeName>
    >
    > <Value>stylesheet</Value>
    >
    > </StyleAttribute>
    >
    > <StyleAttribute>
    >
    > <AttributeName>type</AttributeName>
    >
    > <Value>text/css</Value>
    >
    > </StyleAttribute>
    >
    > </StyleSheet>
    >
    > </Page>
    >
    > </Config>
    >
    >
     
    Sahil Malik, Mar 7, 2005
    #2
    1. Advertisements

  3. Guest

    Guest Guest

    Yes 'Config' is a strongly typed dataset. The issue that i am confused about
    right now is that, if vs.net was able to conform the xml document's well
    formed structure as well as its validity with respect to the schema (because
    it generated it in the first place), then the generated (strongly) typed
    dataset shouldnt have any problems with mapping attribute values, shouldnt
    it?

    If we assume for a moment that datamapping was done properly then
    (theoretically) we should be able to get the values of the elements and their
    attributes. So if i can get the following value:
    'language' from the following element
    <AttributeName>language</AttributeName>

    then i should also be able to get this:
    'something' from dsconfiguration.Attribute(0).AttributeName
    <Attribute AttributeName="something" Value="skdj" />

    Also if the dataset were not mapped correctly then i wouldnt have been able
    to see the properties (attributes) of the respective elements (tables).
    Having said that, i still dont know where i am going wrong here.

    p.s. if you'd like me to, i can post the code for the dataset as well as its
    corresponding schema.
    "Sahil Malik" wrote:

    > Dim dsConfiguration As New Config
    >
    > <--- What kind of object is Config?
    >
    > I'm assuming that is your strongly typed dataset?
    >
    > Why the below is happening depends on your schema. Not every schema is
    > directly mapped to a dataset, i.e. Not every schema qualifies to be a
    > dataset.
    >
    > - Sahil Malik
    > http://codebetter.com/blogs/sahil.malik/
    >
    >
    >
    >
    > "Anon" <> wrote in message
    > news:...
    > > I have an XML document that stores configuration settings for an app. I
    > > generated the schema using vs.net and also the corresponding dataset. I

    > can
    > > load the config file (config.xml - below) and get all the data except for

    > the
    > > element attribute values. I cannot figure out why the attribute values

    > return
    > > a value of system.dbnull when the file contains values for those

    > attributes.
    > > The code is as follows:
    > >
    > > config loader .vb
    > >
    > >
    > > Dim dsConfiguration As New Config
    > >
    > > dsConfiguration.ReadXml(Server.MapPath("Config.xml"))
    > >
    > > 'I cannot get the following attribute value title
    > >
    > > Response.Write(dsConfiguration.Page(0).Title)
    > >
    > > 'but this works fine
    > >
    > > Response.Write(dsConfiguration.JavaAttribute(0).AttributeName)
    > >
    > >
    > >
    > >
    > > config.xml
    > >
    > >
    > > <?xml version="1.0" encoding="utf-8" ?>
    > >
    > > <Config xmlns="http://tempuri.org/Config.xsd">
    > >
    > > <Page Title="Some title">
    > >
    > > <MetaTag>
    > >
    > > <Attribute AttributeName="something" Value="skdj" />
    > >
    > > </MetaTag>
    > >
    > > <JavaScript Path="/script.js">
    > >
    > > <JavaAttribute>
    > >
    > > <AttributeName>language</AttributeName>
    > >
    > > <Value>JavaScript</Value>
    > >
    > > </JavaAttribute>
    > >
    > > </JavaScript>
    > >
    > > <StyleSheet Path="/style.css">
    > >
    > > <StyleAttribute>
    > >
    > > <AttributeName>rel</AttributeName>
    > >
    > > <Value>stylesheet</Value>
    > >
    > > </StyleAttribute>
    > >
    > > <StyleAttribute>
    > >
    > > <AttributeName>type</AttributeName>
    > >
    > > <Value>text/css</Value>
    > >
    > > </StyleAttribute>
    > >
    > > </StyleSheet>
    > >
    > > </Page>
    > >
    > > </Config>
    > >
    > >

    >
    >
    >
     
    Guest, Mar 7, 2005
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MeDhanush
    Replies:
    0
    Views:
    226
    MeDhanush
    Sep 9, 2003
  2. Brad Allison

    typed vs strong typed dataset

    Brad Allison, Jul 21, 2004, in forum: Microsoft ADO .NET
    Replies:
    3
    Views:
    665
    Brad Allison
    Jul 21, 2004
  3. Fabiano
    Replies:
    1
    Views:
    609
    Matt Berther
    Sep 21, 2004
  4. A.M-SG
    Replies:
    6
    Views:
    1,431
    Steven Cheng[MSFT]
    Feb 1, 2006
  5. deko

    How to retrieve TimeSpan from typed DataSet?

    deko, Mar 7, 2006, in forum: Microsoft ADO .NET
    Replies:
    1
    Views:
    254
Loading...

Share This Page