xml file...

R

RAB

I am using visual studio web developer express 2005.

I have the following xml file:

<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:eek:d="urn:schemas-microsoft-com:eek:fficedata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="PIMeds.xsd"
generated="2009-02-22T13:27:28">
<PIMeds>
<IdNum>25</IdNum>
<BrandName>Doribax</BrandName>
<GenericName>Doripenem</GenericName>
<MedType>Antibiotic</MedType>
<PIRevision>October 2007</PIRevision>
<PILink>PIOctober2007/Doribax_10_12_07.pdf</PILink>
<Use>Abdominal / UTI</Use>
<Month>10</Month>
<Year>2007</Year>
<FDAApproval>2007-10-12T00:00:00</FDAApproval>
<ApprovalType>New Molecular Entity</ApprovalType>
</PIMeds>
</dataroot>

when I use an XMLDataSource and a gridview I get an "error rendering
the control"..."the gridview did not have an attributes or properties
of which to generate columns..."

Does anyone know how to work around this? I think the format of my
XML file is the problem.

Thanks,
RABMissouri
 
M

Martin Honnen

RAB said:
Does anyone know how to work around this? I think the format of my
XML file is the problem.

When you bind an XmlDataSource to a tabular control then attributes in
the XML are treated as columns but your XML sample does not have any
attributes.
However the XML you have should work with a DataSet and the ReadXml
method e.g.
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("file.xml"))
gridView1.DataSource = ds.Tables["PIMeds"];
gridView1.DataBind();

If you wanted to use the XmlDataSource then you would need to provide an
XSLT stylesheet to transform the XML you have into one where the data
you want to bind is exposed as attributes.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top