PC Review


Reply
Thread Tools Rate Thread

Retrieve attributes from xml document using typed dataset

 
 
=?Utf-8?B?QW5vbg==?=
Guest
Posts: n/a
 
      7th Mar 2005
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>


 
Reply With Quote
 
 
 
 
Sahil Malik
Guest
Posts: n/a
 
      7th Mar 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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>
>
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?QW5vbg==?=
Guest
Posts: n/a
 
      7th Mar 2005
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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>
> >
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what encoding does system.xml.xmldocument.save(string path) use to save the xml document if there is no <?xml... in the front of the xml document? Daniel Microsoft C# .NET 7 17th Mar 2007 11:29 AM
what encoding does system.xml.xmldocument.save(string path) use to save the xml document if there is no <?xml... in the front of the xml document? Daniel Microsoft Dot NET Framework 5 17th Mar 2007 10:11 AM
what encoding does system.xml.xmldocument.save(string path) use to save the xml document if there is no <?xml... in the front of the xml document? Daniel Microsoft Dot NET 1 15th Mar 2007 10:37 AM
Typed DataSet Vs Un-Typed DataSet =?Utf-8?B?Sm9iIExvdA==?= Microsoft Dot NET 1 22nd Feb 2005 11:18 AM
Cast weakly typed DataSet to a strongly typed dataset??? Microsoft Dot NET 0 18th Sep 2003 10:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:43 AM.