question about throwing some xml into a grid view at runtime

A

Adam Sandler

Hello,

Before I begin, here's some background to the problem. I'm working on
a web app which deals with maps. Via a browser, the users can zoom in,
zoom out, and pan around a map of their geographic region. The users
can also click a button called "identify". When they do this the mouse
pointer changes to a crosshair and when they click on the map, the
polygon under the cursor is captured and passed in a query to the
database... what is returned is information about that "identified"
point

The results returned are in a XML format. Some 3rd party software I'm
using is the broker here and that product returns all queries as XML...
I cannot change it. If you're curious, here's a sample of what the
results look like:

<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<RESPONSE>
<FEATURES>
<FEATURE>
<ENVELOPE minx="-104.812676033658" miny="38.8389470054157"
maxx="-104.81244896185" maxy="38.839049932579" />
<FIELDS>
<FIELD name="FID" value="152474" />
<FIELD name="SHAPE_AREA" value="2008.734375" />
<FIELD name="SHAPE_LEN" value="189.714570418" />
</FIELDS>
</FEATURE>
</FEATURES>
</RESPONSE>
</ARCXML>

For display, I was thinking of throwing these results into a
gridview... here's what I've written:

Sub showXML(ByVal s As String)
Dim ds As New DataSet
Dim gv As New GridView

Dim xr As System.Xml.XmlReader =
System.Xml.XmlReader.Create(New System.IO.StringReader(s))

ds.ReadXml(xr)

gv.DataSource = ds
gv.DataBind()
Me.GridViewPlaceHolder.Controls.Add(gv)
End Sub

And at runtime, this is what the gridview looks like:

ARCXML_Id version
0 1.1

hmmmm... I was under the impression one could throw XML into a gridview
and the component knew how to handle it automatically... i.e., the tags
describing the data automatically became column headings and the values
automatically became rows??? Also, I don't have a tag "ARCXML_Id"...
where did the "_Id" get appended to the ARCXML?

Why does only the first line of the results make it into the gridview?
How can I get all the XML into the gridview? Suggestions as to where
I'm going wrong with my implementation are greatly appreciated.

Thanks!
 
K

Kevin Spencer

No need for a grid view. Just use an XSLT transform.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

What You Seek Is What You Get.
 
A

Adam Sandler

Kevin said:
No need for a grid view. Just use an XSLT transform.

Thanks for the reply... a gridview is very powerful don't you think?
There's a lot of things I can do with a gridview versus some xsl which
creates a clunky HTML table...

<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template
match="/">
<html>
<body>
<h2>Results</h2>
<table border="1">
<tr>
<th align="left">FID</th>
<th align="left">SHAPE_AREA</th>
<th align="left">SHAPE_LEN</th>
</tr>
<xsl:for-each select="FEATURE/FIELDS">
<tr>
<td><xsl:value-of select="FID"/></td>
<td><xsl:value-of select="SHAPE_AREA"/></td>
<td><xsl:value-of select="SHAPE_LEN"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template></xsl:stylesheet>

Are you saying a gridview cannot be used or is that just your personal
preference?
 
K

Kevin Spencer

A GridView creates an HTML table as well. It all depends on what you want to
do with the data displayed. I assumed that since it is in an XML file that
it would not need to be changed by the user. Assuming that the data in the
XML file is read-only, there's nothing clunky about using an XSLT transform
to insert it into your page. In fact, ASP.Net includes Controls for doing
this. See the documentation for System.Web.UI.WebControls.Xml:

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.xml.aspx.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

What You Seek Is What You Get.
 
K

Kevin Spencer

BTW, I should mention that an additional advantage of using XSLT with XML
instead of a GridView is that there is no limitation on how you format the
XML with the XSLT solution. In fact, you can format it any of many different
ways. We have a service that gets METAR weather data from Automated Weather
Observation Stations (AWOS) and sends it to the National Weather Service. It
creates log files by means of a Log class that is serializable as XML. I
created an ASPX page that displays the log simply by getting the log file
and performing an XSLT transform on it to embed it in the page. Here is an
example:

http://www.dynamicsystems.com/weatherservices/DistributionReport.aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

What You Seek Is What You Get.
 
A

Adam Sandler

Kevin said:
A GridView creates an HTML table as well. It all depends on what you want to

Thanks again... I understand...
there's nothing clunky about using an XSLT transform

Let me explain further, I wasn't knocking the methodology per se. What
I was knocking is with the xml transform, I'm still writing HTML. With
things like visual environments and ASP, I frankly don't spend a lot of
time on markup that much anymore.

For my business needs, would I rather get caught up in <tr></tr> and
<td></td> maintenance he|| or would I rather dump the data into an ASP
component and let the server run with it? Albeit, I'd only have to
write the table once -- but I vote for the latter. Especially when
faced with always changing customer requirements -- I'd prefer to spend
time on content rather than markup if a gridview can assemble a table
automatically from some XML in memory as I was led to believe.

Also, what I posted originally is a simplistic view of what I'm doing.
While all the XML is indeed read only, there could be a lot of data
returned. And depending on what feature the user selects on the map to
identify by, the XML could come back with different fields in it... so
in that case, I'll be writing <tr></tr> and <td></td> for one type of
results, and I'll be doing it for the XML which parses out into 5
columns, and again for the XML which parses out into 10 columns, etc...


Thanks for all the help thus far!
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top