Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: ASP.NET 2- Can't read data in XML file >Thread Next - Re: ASP.NET 2- Can't read data in XML file Re: ASP.NET 2- Can't read data in XML fileTo: NULL Date: 4/3/2006 6:00:00 PM Thanks Martin, I will give this a try and let you know. Thanks again! "Martin Honnen" <mahotrash@y...> wrote in message news:OAuOdrxVGHA.2208@T...... > > > noone wrote: > > >> I've seen many complaints about the exact some thing I'm seeing. >> It appears that the XML file has to have attributes or it wont work using >> the VWD and using Xmldatasource and Gridview objects. >> I'd say it's bug, I'd find it hard to believe that this is by design. > > You can then first run an XSLT transformation on the original XML to > convert child elements to attributes for instance. The XmlDataSource has > members to allow that. > > Here is a simple example that works for me with ASP.NET 2.0: > > XML file test2006040201.xml is for instance > > <?xml version="1.0" encoding="UTF-8"?> > <gods> > <god> > <name>Kibo</name> > <power>42</power> > </god> > <god> > <name>Xibo</name> > <power>-42</power> > </god> > </gods> > > where the god elements are the records to be displayed within the table > and the child elements name and power the columns. > > Then I have written a generic XSLT stylesheet (e.g. test2006040301Xsl.xml) > that transforms the leaf child elements (e.g. name and power) to > attributes: > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> > > <xsl:output method="xml" /> > > <xsl:template match="@* | node()"> > <xsl:copy> > <xsl:apply-templates select="@* | node()" /> > </xsl:copy> > </xsl:template> > > <xsl:template match="*[*[not(*)]]"> > <xsl:copy> > <xsl:apply-templates select="*" mode="element-to-attribute" /> > </xsl:copy> > </xsl:template> > > <xsl:template match="*" mode="element-to-attribute"> > <xsl:attribute name="{name()}"><xsl:value-of select="." > /></xsl:attribute> > </xsl:template> > > </xsl:stylesheet> > > > You could then apply that in an ASP.NET page as follows: > > <form runat="server"> > <asp:XmlDataSource > id="godSource1" > runat="server" > DataFile="test2006040201.xml" > TransformFile="test2006040301Xsl.xml" > XPath="gods/god" /> > > > <asp:GridView > id="GridView1" > DataSourceID="godSource1" > runat="server"> > </asp:GridView> > > </form> > > Let us now whether that helps. As said the stylesheet is generic so it > hopefully works with your original XML > > <?xml version="1.0" standalone="yes"?> > <webstats> > <app> > <dir>\\w3svc72802400\\</dir> > <dns>Fbot</dns> > <nbserver>\\fiscmmk410win</nbserver> > <alias>Fbot</alias> > <sname>fiscmmk410win</sname> > <port>80</port> > </app> > </webstats> > > as well if you want the app element(s) to be the record(s)/row(s) and the > dir, dns and so on elements to be the columns. > > > -- > > Martin Honnen --- MVP XML > http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
