Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Need help with xpath and xml

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Showjumper - 24 Jul 2007 20:30 GMT
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>
Manish Bafna - 25 Jul 2007 05:30 GMT
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/2003/10/07/30888.aspx
Signature

Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

> Hi i posted this on the dotnet xml group but that group does not get much
> traffic so i thought to post here.
[quoted text clipped - 47 lines]
>
> </Photos>
Showjumper - 25 Jul 2007 14:27 GMT
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
> Hi,
> Try this code:
[quoted text clipped - 68 lines]
>>
>> </Photos>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.