473,378 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

XPath GetAttributes Problem

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
2 2329
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
4
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a...
3
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method...
4
by: xenny | last post by:
Hi, I'm trying to see if a file (exportfile) is set to read only using File::GetAttributes: if ((File::GetAttributes(exportfile.c_str()) & FileAttributes::ReadOnly) != 0); {...
3
by: abcd_68 | last post by:
Hi there, I'm using, for the first time, the JDK1.5 Xpath API. I need to find elements in a Hibernate-generated .hbm.xml file. These files come with a <!DOCTYPE header mentioning a remote URL....
5
by: daveyand | last post by:
Guys, I'm having issues with getAttributes. I have done the following. attr_list = document.getElementById("image_id").getAttributes(); I want to be able to loop around the attributes...
6
by: J.Marsch | last post by:
I must be completely losing my mind. I have some code that writes to config files. It works great with app.config files, but fails miserably with web.config files. For the life of me, I cannot...
5
by: jorgedelgadolopez | last post by:
Hi all, I am using the xpathnavigator evaluate function on .net (xpath 1 right?). Now I need to expand the code to do multiple contains, compare dates (such as 'before', 'between' and 'after'),...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.