DeonM
asked on
Bind XMLNode to ASP.Net GridView
I'm having difficulties binding a XMLNode to gridview.
If i use a xmlnodereader and read it into a dataset, the dataset has 4 tables.
How can i bind the dataset to the gridview to show all the info from the 4 tables?
Basically i wish to display the vehicle spec information in the grid.
I have attached example of the xmlnode i retrieve from the data supplier.
Any help greatly appreciated.
xmlnode.txt
If i use a xmlnodereader and read it into a dataset, the dataset has 4 tables.
How can i bind the dataset to the gridview to show all the info from the 4 tables?
Basically i wish to display the vehicle spec information in the grid.
I have attached example of the xmlnode i retrieve from the data supplier.
Any help greatly appreciated.
xmlnode.txt
Guess I should provide an example. Here's the resulting pattern of name=value elements generated by the XSL-T below.
<CarInfo>
<Spec>
<Category>Engine !AMP! Gearbox</Category>
<Name>Accel 0-100</Name>
<Value>11.3 Seconds</Value>
</Spec><Spec>
Essentially you get a flattened set of spec values over all categories.
<CarInfo>
<Spec>
<Category>Engine !AMP! Gearbox</Category>
<Name>Accel 0-100</Name>
<Value>11.3 Seconds</Value>
</Spec><Spec>
Essentially you get a flattened set of spec values over all categories.
<?xml version='1.0'?>
<xsl:stylesheet
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
version='1.0'>
<xsl:output method='xml'/>
<xsl:template match='/'>
<CarInfo>
<xsl:apply-templates select='//Spec' />
</CarInfo>
</xsl:template>
<xsl:template match='Spec'>
<Spec>
<Category>
<xsl:value-of select='../@name'/>
</Category>
<Name>
<xsl:value-of select='@name'/>
</Name>
<Value>
<xsl:value-of select='text()'/>
</Value>
</Spec>
</xsl:template>
</xsl:stylesheet>
ASKER
Thanks for your reply, how i understand this is, I saved the example as my schema file and read it into my dataset. But i receive and error on the ReadXML line.
I receive the following error:
"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."
Thanks for your help, this XML confuses me.
I receive the following error:
"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."
Thanks for your help, this XML confuses me.
string xmlstring = SessionValues.VehicleSpec.OuterXml.ToString();
DataSet ds = new DataSet();
System.IO.StringReader rdr = new System.IO.StringReader(xmlstring);
ds.ReadXmlSchema("\\xmlschema.xsd");
ds.ReadXml(rdr);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The XML sample you provided looks pretty straightforward so this should not be a problem.