Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Need help with xpath and xml (http://www.velocityreviews.com/forums/t524496-need-help-with-xpath-and-xml.html)

Showjumper 07-24-2007 07:30 PM

Need help with xpath and xml
 
Hi i posted this on the dotnet xml group but that group does not get much
traffic so i thought to post here.

I have a photo gallery that works by looping thru the images, making an xml
file and then binding it to the datalist. The gallery part works fine. My
next task was to make an admin page so that captions for each of the photos
could be edited. In the edititemtemplate i have a textbox for the caption
edit and 2 linkbuttons. Using the following syntax i can locate a specific
node and edit the caption. My main problem is that it only works when the ID
is hardcoded. Only issue i have right now is how to pass in the ID
dynamically based on which image is clicked. The xml structure is below as
well. The other alternative xml structure i used was to have the ID its own
element as <PhotoID>1 </PhotoID> as an example. In this case i could set the
DataKeyField to PhotoID but i was not able to edit the Caption node using
this structure - i had issue with the xpath syntax.. I was able to edit the
caption if the ID was an attribute of the Photo element. Just need some help
in making htis work. Thanks in advance Ashok
Dim nodeList As XmlNodeList =
xmlDoc.SelectNodes(String.Format("/Photos/Photo[@ID='{0}']", ID))

nodeList(0).ChildNodes(0).InnerText = Caption

xmlDoc.Save(filepath)



<Photos>

<Photo ID="1">

<Caption>FGHFGHDFG</Caption>

<FileName>DSC00067.jpg</FileName>

<FilePath>~/photos/Stills/DSC00067.jpg</FilePath>

<ThumbnailFilePath>~/photos/Stills/thumbnails/DSC00067.jpg</ThumbnailFilePath>

</Photo>

<Photo ID="2">

<Caption>FGHFGHDFG</Caption>

<FileName>DSC00068.jpg</FileName>

<FilePath>~/photos/Stills/DSC00068.jpg</FilePath>

<ThumbnailFilePath>~/photos/Stills/thumbnails/DSC00068.jpg</ThumbnailFilePath>

</Photo>

</Photos>



=?Utf-8?B?TWFuaXNoIEJhZm5h?= 07-25-2007 04:30 AM

RE: Need help with xpath and xml
 
Hi,
Try this code:
string xpath = "//("/Photos/Photo[@ID =$ID]";
XPathExpression expr = DynamicContext.Compile(xpath);
OR
//Run-time
DynamicContext ctx = new DynamicContext();
ctx.AddVariable("ID", txtID.Text);
expr.SetContext(ctx);
XPathNodeIterator custData = customers.Select(expr);
ref:http://weblogs.asp.net/cazzu/archive.../07/30888.aspx
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



"Showjumper" wrote:

> Hi i posted this on the dotnet xml group but that group does not get much
> traffic so i thought to post here.
>
> I have a photo gallery that works by looping thru the images, making an xml
> file and then binding it to the datalist. The gallery part works fine. My
> next task was to make an admin page so that captions for each of the photos
> could be edited. In the edititemtemplate i have a textbox for the caption
> edit and 2 linkbuttons. Using the following syntax i can locate a specific
> node and edit the caption. My main problem is that it only works when the ID
> is hardcoded. Only issue i have right now is how to pass in the ID
> dynamically based on which image is clicked. The xml structure is below as
> well. The other alternative xml structure i used was to have the ID its own
> element as <PhotoID>1 </PhotoID> as an example. In this case i could set the
> DataKeyField to PhotoID but i was not able to edit the Caption node using
> this structure - i had issue with the xpath syntax.. I was able to edit the
> caption if the ID was an attribute of the Photo element. Just need some help
> in making htis work. Thanks in advance Ashok
> Dim nodeList As XmlNodeList =
> xmlDoc.SelectNodes(String.Format("/Photos/Photo[@ID='{0}']", ID))
>
> nodeList(0).ChildNodes(0).InnerText = Caption
>
> xmlDoc.Save(filepath)
>
>
>
> <Photos>
>
> <Photo ID="1">
>
> <Caption>FGHFGHDFG</Caption>
>
> <FileName>DSC00067.jpg</FileName>
>
> <FilePath>~/photos/Stills/DSC00067.jpg</FilePath>
>
> <ThumbnailFilePath>~/photos/Stills/thumbnails/DSC00067.jpg</ThumbnailFilePath>
>
> </Photo>
>
> <Photo ID="2">
>
> <Caption>FGHFGHDFG</Caption>
>
> <FileName>DSC00068.jpg</FileName>
>
> <FilePath>~/photos/Stills/DSC00068.jpg</FilePath>
>
> <ThumbnailFilePath>~/photos/Stills/thumbnails/DSC00068.jpg</ThumbnailFilePath>
>
> </Photo>
>
> </Photos>
>
>
>


Showjumper 07-25-2007 01:27 PM

Re: Need help with xpath and xml
 
Thanks but i am still unclear on how to use this. Also i think part of my
issue is how to do i set the datakeyfield of the datalist so that i can get
this ID and pass it into my update sub.

Ashok
"Manish Bafna" <ManishBafna@discussions.microsoft.com> wrote in message
news:D274AEEC-A898-421B-BBE6-4A88B1555D21@microsoft.com...
> Hi,
> Try this code:
> string xpath = "//("/Photos/Photo[@ID =$ID]";
> XPathExpression expr = DynamicContext.Compile(xpath);
> OR
> //Run-time
> DynamicContext ctx = new DynamicContext();
> ctx.AddVariable("ID", txtID.Text);
> expr.SetContext(ctx);
> XPathNodeIterator custData = customers.Select(expr);
> ref:http://weblogs.asp.net/cazzu/archive.../07/30888.aspx
> --
> Hope this helps.
> Thanks and Regards.
> Manish Bafna.
> MCP and MCTS.
>
>
>
> "Showjumper" wrote:
>
>> Hi i posted this on the dotnet xml group but that group does not get much
>> traffic so i thought to post here.
>>
>> I have a photo gallery that works by looping thru the images, making an
>> xml
>> file and then binding it to the datalist. The gallery part works fine. My
>> next task was to make an admin page so that captions for each of the
>> photos
>> could be edited. In the edititemtemplate i have a textbox for the caption
>> edit and 2 linkbuttons. Using the following syntax i can locate a
>> specific
>> node and edit the caption. My main problem is that it only works when the
>> ID
>> is hardcoded. Only issue i have right now is how to pass in the ID
>> dynamically based on which image is clicked. The xml structure is below
>> as
>> well. The other alternative xml structure i used was to have the ID its
>> own
>> element as <PhotoID>1 </PhotoID> as an example. In this case i could set
>> the
>> DataKeyField to PhotoID but i was not able to edit the Caption node using
>> this structure - i had issue with the xpath syntax.. I was able to edit
>> the
>> caption if the ID was an attribute of the Photo element. Just need some
>> help
>> in making htis work. Thanks in advance Ashok
>> Dim nodeList As XmlNodeList =
>> xmlDoc.SelectNodes(String.Format("/Photos/Photo[@ID='{0}']", ID))
>>
>> nodeList(0).ChildNodes(0).InnerText = Caption
>>
>> xmlDoc.Save(filepath)
>>
>>
>>
>> <Photos>
>>
>> <Photo ID="1">
>>
>> <Caption>FGHFGHDFG</Caption>
>>
>> <FileName>DSC00067.jpg</FileName>
>>
>> <FilePath>~/photos/Stills/DSC00067.jpg</FilePath>
>>
>> <ThumbnailFilePath>~/photos/Stills/thumbnails/DSC00067.jpg</ThumbnailFilePath>
>>
>> </Photo>
>>
>> <Photo ID="2">
>>
>> <Caption>FGHFGHDFG</Caption>
>>
>> <FileName>DSC00068.jpg</FileName>
>>
>> <FilePath>~/photos/Stills/DSC00068.jpg</FilePath>
>>
>> <ThumbnailFilePath>~/photos/Stills/thumbnails/DSC00068.jpg</ThumbnailFilePath>
>>
>> </Photo>
>>
>> </Photos>
>>
>>
>>





All times are GMT. The time now is 05:04 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.