By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,016 Members | 1,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,016 IT Pros & Developers. It's quick & easy.

XPath GetAttributes Problem

P: n/a
Hi

I need to select several nodes (title) on an xml document based on an atrribute(user) and then read from each selected element (title) another attribute(nomequiz).

Here's my code so far but it isn't working..

Would really appreciate some help. Got really stuck. I already tried with xmlDocument instead but it didn't work either.

If Session("user") <> "" Then

Dim strUser As String = Session("user").ToString

'private quizzes
strX += "<tr><td><b>Quizzes Privados</b></td></tr>"
Dim xDocPvt As New XPathDocument(Server.MapPath("quizpvt.xml"))
Dim xNav As XPathNavigator = xDocPvt.CreateNavigator()
Dim xNodeIterator As XPathNodeIterator
strTitlePvt = "/quiz/title[@user='" & strUser & "']"
xNodeIterator = xNav.Select("/quiz/title[@user='" & strUser & "']")
While xNodeIterator.MoveNext()
strX += "<tr><td><a href=quizexplanation.aspx?" & strUser & ">" & xNodeIterator.Current.GetAttribute("nomequiz", Nothing) & "</a><br>"
End While
strX += strUser & "</tr></table>"

Else
strX += "</table>"
End If

ListaQuizScreen.InnerHtml = strX
Here's a sample of my xml file:

<quiz xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="quizpvt.xsd">
<title cat="Inform?tica" created="2005-03-08" user="sofia" nomequiz="Powerpoint B?sico">
<mchoice>
<question>Se quiser visualizar a sua apresenta??o em modo de ecran inteiro, pode...:</question>
<answer>Clicar em Apresenta??es</answer>
<answer correct="Yes">Premir a tecla F5</answer>
<answer>Premir as teclas F + 5</answer>
<answer>Premir as teclas Ctrl + Enter</answer>
<explanation>Dever? premir a tecla de fun??o F5. Tamb?m pode ir ao menu Apresenta??es e escolher Ver apresenta??o de diapositivos.</explanation>
<training>http://www.microsoft.pt</training>
</mchoice>
<mchoice>
<question>Se quiser visualizar a sua apresenta??o em modo de ecran inteiro, pode...:</question>
<answer>Clicar em Apresenta??es</answer>
<answer correct="Yes">Premir a tecla F5</answer>
<answer>Premir as teclas F + 5</answer>
<answer>Premir as teclas Ctrl + Enter</answer>
<explanation>Dever? premir a tecla de fun??o F5. Tamb?m pode ir ao menu Apresenta??es e escolher Ver apresenta??o de diapositivos.</explanation>
<training>http://www.microsoft.pt</training>
</mchoice>
</title>
</quiz>
--------------------------------
From: yonta beja

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>OCCzq7DPSEOfNkl1qP6ZBw==</Id>
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
yonta via .NET 247 wrote:

I need to select several nodes (title) on an xml document based on an atrribute(user) and then read from each selected element (title) another attribute(nomequiz).

Here's my code so far but it isn't working..


You forgot to tell us what doesn't seem to be working.

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #2

P: n/a
Hi Yonta,

I'd say XmlDocument should work in this case. The following are some code
sample you might want to give it a try:

If Session("user") <> "" Then

Dim strUser As String = Session("user").ToString

'private quizzes
strX += "<tr><td><b>Quizzes Privados</b></td></tr>"

Dim xDocPvt As New XmlDocument()

xDocPvt.Load(Server.MapPath("quizpvt.xml"))

Dim titleNodes as XmlNodeList

titleNodes = doc.SelectNodes("//title[@user='" & strUser & "']")

Dim title as XmlElement

for each title in titleNodes
strX += "<tr><td><a href=quizexplanation.aspx?" & strUser & ">" &
title.GetAttribute("nomequiz") & "</a><br>"
next

strX += strUser & "</tr></table>"

Else
strX += "</table>"
End If

ListaQuizScreen.InnerHtml = strX

--
Thanks,
Yingzi Le
LongHorn SDK Team

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: yonta via .NET 247 <an*******@dotnet247.com>
X-Newsreader: AspNNTP 1.50 (Matthew Reynolds Consulting)
Subject: XPath GetAttributes Problem
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <eB*************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.xml
Date: Mon, 21 Mar 2005 12:49:26 -0800
NNTP-Posting-Host: 81-86-69-114.dsl.pipex.com 81.86.69.114
Lines: 1
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGP08.phx.gbl!TK2MSFTNGP1
0.phx.gblXref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.xml:25911
X-Tomcat-NG: microsoft.public.dotnet.xml

Hi

I need to select several nodes (title) on an xml document based on an atrribute(user) and then read from each selected element (title) another
attribute(nomequiz).
Here's my code so far but it isn't working..

Would really appreciate some help. Got really stuck. I already tried with xmlDocument instead but it didn't work either.
If Session("user") <> "" Then

Dim strUser As String = Session("user").ToString

'private quizzes
strX += "<tr><td><b>Quizzes Privados</b></td></tr>"
Dim xDocPvt As New XPathDocument(Server.MapPath("quizpvt.xml"))
Dim xNav As XPathNavigator = xDocPvt.CreateNavigator()
Dim xNodeIterator As XPathNodeIterator
strTitlePvt = "/quiz/title[@user='" & strUser & "']"
xNodeIterator = xNav.Select("/quiz/title[@user='" & strUser & "']")

While xNodeIterator.MoveNext()
strX += "<tr><td><a href=quizexplanation.aspx?" & strUser & ">" & xNodeIterator.Current.GetAttribute("nomequiz", Nothing) & "</a><br>" End While
strX += strUser & "</tr></table>"

Else
strX += "</table>"
End If

ListaQuizScreen.InnerHtml = strX
Here's a sample of my xml file:

<quiz xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="quizpvt.xsd"><title cat="Inform?tica" created="2005-03-08" user="sofia" nomequiz="Powerpoint B?sico"> <mchoice>
<question>Se quiser visualizar a sua apresenta??o em modo de ecran inteiro, pode...:</question> <answer>Clicar em Apresenta??es</answer>
<answer correct="Yes">Premir a tecla F5</answer>
<answer>Premir as teclas F + 5</answer>
<answer>Premir as teclas Ctrl + Enter</answer>
<explanation>Dever? premir a tecla de fun??o F5. Tamb?m pode ir ao menu Apresenta??es e escolher Ver apresenta??o de diapositivos.</explanation> <training>http://www.microsoft.pt</training>
</mchoice>
<mchoice>
<question>Se quiser visualizar a sua apresenta??o em modo de ecran inteiro, pode...:</question> <answer>Clicar em Apresenta??es</answer>
<answer correct="Yes">Premir a tecla F5</answer>
<answer>Premir as teclas F + 5</answer>
<answer>Premir as teclas Ctrl + Enter</answer>
<explanation>Dever? premir a tecla de fun??o F5. Tamb?m pode ir ao menu Apresenta??es e escolher Ver apresenta??o de diapositivos.</explanation> <training>http://www.microsoft.pt</training>
</mchoice>
</title>
</quiz>
--------------------------------
From: yonta beja

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>OCCzq7DPSEOfNkl1qP6ZBw==</Id>


Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.