Retrieve attributes from xml document using typed dataset

G

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>
 
S

Sahil Malik

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/
 
G

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top