xml file...

  • Thread starter Thread starter RAB
  • Start date Start date
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:od="urn:schemas-microsoft-com:officedata"
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
 
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.
 
Back
Top