Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > using Gridview xpath to get xml node

Reply
Thread Tools

using Gridview xpath to get xml node

 
 
kpg
Guest
Posts: n/a
 
      01-06-2009

Hi all,

I have a gridview bound to an xmldatasource using itemtemplets and xpath
to bind the xml data to the grid.

I have a (hidden) column in the grid that contains a particular child
node from my data set.

So my xml is of the form:

<xml>
<record>
<data1>Some data</data1>
<data2>Some other data</data2>
<data3>
<childdata1>child data</childdata1>
<childdata2>more child data</childdata2>
</data3>
</record>
</xml>


The gridview is as follows:


<asp:TemplateField HeaderText="col1">
<ItemTemplate>
<%#XPath("data1")%>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="col2">
<ItemTemplate>
<%#XPath("data2")%>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="col3">
<ItemTemplate>
<%#XPath("data3")%>
</ItemTemplate>
</asp:TemplateField>


what I get in col3 is:

child datamore child data

what I want is:

<childdata1>child data</childdata1><childdata2>more child data
</childdata2>


So that I can use javascript to parse the xml child node fragment and
build a dynamic info box in response to some user event.

Is there a way to get the outer xml instead of only the text?

Thanks,
kpg
 
Reply With Quote
 
 
 
 
Stan
Guest
Posts: n/a
 
      01-07-2009
On 6 Jan, 21:06, kpg <(E-Mail Removed)> wrote:
> Hi all,
>
> I have a gridview bound to an xmldatasource using itemtemplets and xpath
> to bind the xml data to the grid.
>
> I have a (hidden) column in the grid that contains a particular child
> node from my data set.
>
> So my xml is of the form:
>
> <xml>
> * * * * <record>
> * * * * * * * * <data1>Some data</data1>
> * * * * * * * * <data2>Some other data</data2>
> * * * * * * * * <data3>
> * * * * * * * * * * * * <childdata1>child data</childdata1>
> * * * * * * * * * * * * <childdata2>more child data</childdata2>
> * * * * * * * * </data3>
> * * * * </record>
> </xml>
>
> The gridview is as follows:
>
> <asp:TemplateField HeaderText="col1">
> * * * * <ItemTemplate>
> * * * * * * * * <%#XPath("data1")%>
> * * * * </ItemTemplate>
> </asp:TemplateField>
>
> <asp:TemplateField HeaderText="col2">
> * * * * <ItemTemplate>
> * * * * * * * * <%#XPath("data2")%>
> * * * * </ItemTemplate>
> </asp:TemplateField>
>
> <asp:TemplateField HeaderText="col3">
> * * * * <ItemTemplate>
> * * * * * * * * <%#XPath("data3")%>
> * * * * </ItemTemplate>
> </asp:TemplateField>
>
> what I get in col3 is:
>
> child datamore child data
>
> what I want is:
>
> <childdata1>child data</childdata1><childdata2>more child data
> </childdata2>
>
> So that *I can use javascript to parse the xml child node fragment and
> build a dynamic info box in response to some user event.
>
> Is there a way *to get the outer xml instead of only the text?
>
> Thanks,
> kpg


Hi

Are you aware that xml datasources only work with the data in
attribute form, unless you supply a transform file?
 
Reply With Quote
 
 
 
 
kpg
Guest
Posts: n/a
 
      01-07-2009
> Are you aware that xml datasources only work with the data in
> attribute form, unless you supply a transform file?



Well, I'm not sure what you mean. I am using a transform file to
provide sorting of my source xml. If by attribute form you mean the
text must be only in attributes? If so I must disagree in that the
technique I presented in my post is yeilding the results I stated, and
none of the data is in attributes - however, I'm sure I'm
misunderstanding what you said.

Dispite all that, I want to be able to access the data in my data3 node
from the example including the angle brackets (that is, as xml),
otherwise it is impossible to parse the data.

I have tried to pass the xpath evaluation to a shared function like
this:

<%#MyFunction(XPath("data3"))%>

pubilc shared function MyFunction(v as string) as string

But there also v is only the text, not the outerXML.

What I could do is pass a unique key to this function that ids the data
I want from the xml, but this is a shared function so I do not have
access to the class xmldatasource or any session variables.

I further attempted to add the data on the rowcreated gridview event,
This seemd promising, but I could not find a way to actually modify cell
values from this event.

I suppose what I could do is manually add the data to the grid, after
databinding - is this possible?

The only concern I have with this is that I do allow sorting and
filtering of the grid (via xmldatasource xpath and xsl file changes) so I
will need to re-add the data each time - it would be nice if this were
'automated'.

kpg
 
Reply With Quote
 
kpg
Guest
Posts: n/a
 
      01-07-2009
Resolved, but using a different technique.

I used the row databound event to retrieve the datakey, then using the
xml from the datasource I was able to do an xpath query and get the node
I wanted and set the cell text - this almost worked...

Problem was since the column is hidden it is not rendered in the html. I
knew this and thought I had the whole hidden column thing resolved
becuase I used the technique of setting the column to hidden in the row
created event - but alas it was not part of the html (I assumed it would
be there with a display attribute of none). This technique did seem to
bind the data to the hidden column though in that the data was in the
viewstate (which grew considerably).

So while the data was represented in the viewstate, I figured what the
heck, and I simply added the data to an 'array' of hiddend fields -
which are eaisly accessed by my javascript later.

But the hidden column issue is really a side bar - I essentially wanted
a data island type of structure that I could use client side to build a
detail box when the user hovers on a grid row for a time.

Using the hidden fields built dynamically as rows are data bound
accomplishes this task - but I suspect its a bit of a hack.

I could have used a web service call or some some ajax style server
query, but I wanted the grid to be responsive - I am quite pleased with
the end result, however.

kpg
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl variable $node/text() but $node can non-node-set help! Tjerk Wolterink XML 2 08-24-2006 03:28 AM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
How to get to XML node from an Xpath expressed in string Murtaza Tinwala XML 1 09-20-2004 02:05 PM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments